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-deadfixturesVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade Python version to 3.6 or higher.
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.
Manually verify any reported duplicated fixtures, especially those that return falsy values, to confirm they are truly redundant.
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.
For fixtures potentially used dynamically, consider applying the `@deadfixtures_ignore` decorator to prevent false positives, or manually verify their usage.
Install the plugin using pip: `pip install pytest-deadfixtures` and ensure it's installed in the correct virtual environment if applicable.
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.
Change `dead-fixtures-exclude` to `dead_fixtures_exclude` in your `pytest.ini`, `pyproject.toml`, or `setup.cfg` file.