A simple plugin to list unused fixtures in pytest
Maintained. Last release 5 weeks ago, commits in 1 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install pytest-deadfixturespytest-deadfixtures
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