Registry / testing / pytest-deadfixtures

pytest-deadfixtures

JSON →
library3.1.0pypypi✓ verified 24d ago

pytest-deadfixtures is a simple plugin for pytest that helps identify unused or duplicated fixtures within your test suite. It aids in improving code quality by highlighting fixtures that are no longer needed or could be refactored. The current version is 3.1.0, and the library appears to be actively maintained with a consistent release cadence.

pip install pytest-deadfixtures
INSTALL
IMPORT
SIG · PYTEST-DEADFIXTURE
P
pytest-deadfixtures
testingpythonv3.1.0
Install
2.7s avg
Import
239ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.254s · 31.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 0.224s · 32MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

deadfixtures_ignore
from pytest_deadfixtures import deadfixtures_ignore
Used to explicitly mark fixtures that should not be reported as unused.

To use `pytest-deadfixtures`, install the plugin and then run pytest with the `--dead-fixtures` command-line option. The plugin will analyze your test suite and report any fixtures it identifies as unused. You can optionally use `--dup-fixtures` to find duplicated fixtures or `--show-ignored-fixtures` to list fixtures that have been explicitly ignored. The `deadfixtures_ignore` decorator can be applied to fixtures you intend to leave unused.

import pytest from pytest_deadfixtures import deadfixtures_ignore @pytest.fixture def used_fixture(): return "I am used" @pytest.fixture def unused_fixture(): """This fixture is intentionally unused for demonstration.""" return "I am not used" @pytest.fixture @deadfixtures_ignore def ignored_fixture(): """This fixture will be explicitly ignored by the plugin.""" return "I am ignored" def test_example(used_fixture): assert used_fixture == "I am used" # To run this example and see the unused fixture report, save it as a Python file (e.g., test_fixtures.py) # and execute from your terminal: # pytest --dead-fixtures --show-ignored-fixtures -v test_fixtures.py
Debug
Known issues
breakingVersion 3.0.0 dropped support for Python 3.5. Ensure your environment uses Python 3.6 or newer.
fix
Upgrade Python version to 3.6 or higher.
affects: 3.0.0 and above
gotchaThe `--dead-fixtures` option *does not run your tests*. It is sensitive to errors in the pytest collection step. For CI/CD, it's recommended to run `pytest --dead-fixtures` *after* a successful default `pytest` run.
fix
In your CI pipeline, execute `pytest` first, then a separate command `pytest --dead-fixtures` to ensure test functionality is verified before checking for unused fixtures.
affects: All versions
gotchaWhen using `--dup-fixtures` to find duplicated fixtures, the plugin relies on comparing fixture *return values*. Fixtures that return `None` or other falsy values will be skipped from this analysis. This feature should be used as a hint for manual verification.
fix
Manually verify any reported duplicated fixtures, especially those that return falsy values, to confirm they are truly redundant.
affects: All versions
gotchaBy default, the plugin returns a non-zero exit code if unused fixtures are detected (since version 2.0.0). This will cause CI pipelines to fail if any unused fixtures are found.
fix
Either remove the reported unused fixtures, mark them with `@deadfixtures_ignore`, or configure your CI to allow this specific failure code if you do not want it to be a blocking issue.
affects: 2.0.0 and above
gotchapytest-deadfixtures primarily relies on static analysis to detect unused fixtures. It might not correctly identify fixtures used dynamically (e.g., via `request.getfixturevalue()` or other advanced runtime mechanisms).
fix
For fixtures potentially used dynamically, consider applying the `@deadfixtures_ignore` decorator to prevent false positives, or manually verify their usage.
affects: All versions
Errors
Common errors & fixes
pytest: error: unrecognized arguments: --dead-fixtures
This error occurs because the `pytest-deadfixtures` plugin is not installed or is not accessible in the Python environment where `pytest` is being run.
fix
Install the plugin using pip: `pip install pytest-deadfixtures` and ensure it's installed in the correct virtual environment if applicable.
No dead fixtures found.
This message indicates that `pytest-deadfixtures` analyzed your test suite and found no fixtures that are defined but never used, which can be unexpected if you believe unused fixtures exist.
fix
First, verify that all fixtures you suspect are unused are genuinely not called by any test or other fixture; then, ensure pytest is scanning all relevant test files and directories for fixture definitions.
PytestConfigWarning: Unknown config option: dead-fixtures-exclude
This warning arises when you configure `pytest-deadfixtures` in a file like `pytest.ini` using a hyphenated option name, whereas the plugin expects an underscore in `dead_fixtures_exclude`.
fix
Change `dead-fixtures-exclude` to `dead_fixtures_exclude` in your `pytest.ini`, `pyproject.toml`, or `setup.cfg` file.
Upgrade
Version history
3.1.0latest on PyPI · released Jan 15, 2026
Audit
Dependencies
pytestrequiredCore testing framework that this plugin extends.
Agent activity
13 hits · last 30 days
node
10
Amazon
1
Resources
pytest-deadfixtures — pip install pytest-deadfixtures · libregistry