pytest-deadfixtures 4.0.0


pip install pytest-deadfixtures

  Latest version

Released: Oct 29, 2026

Project Links

Meta
Author: João Luiz Lorencetti
Maintainer: João Luiz Lorencetti, Christian Hartung
Requires Python: >=3.10

Classifiers

Development Status
  • 5 - Production/Stable

Framework
  • Pytest

Intended Audience
  • Developers

Operating System
  • OS Independent

Programming Language
  • Python
  • Python :: 3
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14
  • Python :: 3.15
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Topic
  • Software Development :: Testing

pytest-deadfixtures

PyPI - Version PyPI - Python Version pre-commit.ci status


A simple plugin to list unused or duplicated fixtures in a pytest suite.

Features

  • List unused fixtures in your tests
  • List duplicated fixtures
  • Ignore specific fixtures from analysis with @deadfixtures_ignore

Installation

Install pytest-deadfixtures from PyPI:

pip install pytest-deadfixtures

Usage

Important

The --dead-fixtures option does not run your tests and can also be sensitive to errors during the pytest collection step. If using it in CI, run it after the normal test run:

script:
  - pytest
  - pytest --dead-fixtures

Listing unused fixtures

Run pytest with the --dead-fixtures option:

pytest --dead-fixtures
Hey there, I believe the following fixture(s) are not being used:
Fixture name: some_fixture, location: test_write_docs_when_verbose.py:5

no tests ran

Use verbosity to include fixture docstrings in the report:

pytest --dead-fixtures -v

Listing repeated fixtures

The --dup-fixtures option compares fixture return values to find possible duplicates. Fixtures without a truthy return value are skipped. Treat the report as a hint and verify that the fixtures provide the same functionality before removing one.

Unlike --dead-fixtures, this option runs the tests:

pytest --dup-fixtures
tests/test_deadfixtures.py ........

You may have some duplicate fixtures:
Fixture name: someclass_fixture, location: test_repeated_fixtures.py:12
Fixture name: someclass_samefixture, location: test_repeated_fixtures.py:17

Ignoring specific fixtures

Use the @deadfixtures_ignore decorator to exclude a fixture from the analysis:

import pytest

from pytest_deadfixtures import deadfixtures_ignore


@pytest.fixture
@deadfixtures_ignore
def intentionally_unused_fixture():
    """This fixture won't be reported as unused."""
    return "something"

To see which fixtures are ignored, use --show-ignored-fixtures:

pytest --dead-fixtures --show-ignored-fixtures
No unused fixtures found. Great job!

Ignored fixture(s) 1:
Fixture name: intentionally_unused_fixture, location: conftest.py:10

Projects using it

Contributing

Contributions are welcome. Run the tests with hatch test and check the code with hatch check code before submitting a pull request.

License

Distributed under the terms of the MIT License. pytest-deadfixtures is free and open source software.

Issues

If you encounter any problems, file an issue with a detailed description.

Extras: None
Dependencies:
pytest (>=9.0)