{"id":5424,"library":"pytest-deadfixtures","title":"pytest-deadfixtures","description":"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.","status":"active","version":"3.1.0","language":"en","source_language":"en","source_url":"https://github.com/jllorencetti/pytest-deadfixtures","tags":["pytest","testing","fixtures","code quality","linter"],"install":[{"cmd":"pip install pytest-deadfixtures","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework that this plugin extends.","package":"pytest"}],"imports":[{"note":"Used to explicitly mark fixtures that should not be reported as unused.","symbol":"deadfixtures_ignore","correct":"from pytest_deadfixtures import deadfixtures_ignore"}],"quickstart":{"code":"import pytest\nfrom pytest_deadfixtures import deadfixtures_ignore\n\n@pytest.fixture\ndef used_fixture():\n    return \"I am used\"\n\n@pytest.fixture\ndef unused_fixture():\n    \"\"\"This fixture is intentionally unused for demonstration.\"\"\"\n    return \"I am not used\"\n\n@pytest.fixture\n@deadfixtures_ignore\ndef ignored_fixture():\n    \"\"\"This fixture will be explicitly ignored by the plugin.\"\"\"\n    return \"I am ignored\"\n\ndef test_example(used_fixture):\n    assert used_fixture == \"I am used\"\n\n# To run this example and see the unused fixture report, save it as a Python file (e.g., test_fixtures.py)\n# and execute from your terminal:\n# pytest --dead-fixtures --show-ignored-fixtures -v test_fixtures.py","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade Python version to 3.6 or higher.","message":"Version 3.0.0 dropped support for Python 3.5. Ensure your environment uses Python 3.6 or newer.","severity":"breaking","affected_versions":"3.0.0 and above"},{"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.","message":"The `--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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Manually verify any reported duplicated fixtures, especially those that return falsy values, to confirm they are truly redundant.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"By 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.","severity":"gotcha","affected_versions":"2.0.0 and above"},{"fix":"For fixtures potentially used dynamically, consider applying the `@deadfixtures_ignore` decorator to prevent false positives, or manually verify their usage.","message":"pytest-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).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}