A pytest plugin to list unused fixtures after a test run.
Project description
pytest-unused-fixtures
A pytest plugin to list unused fixtures after a test run.
The plugin watches all fixtures which are used in a test run, and then compares it to all the fixtures available in the same test collection. It then prints out all the fixtures which were not used, groupped by where they were defined.
Running the tests is required to accurately record which fixtures are used, as pytest provides ways of dynamically requesting fixtures, and pure static analysis will not catch those.
Installation
$ pip install pytest-unused-fixtures
Usage
After installing the package, the plugin is enabled by adding the switch --unused-fixtures
.
Paths of fixtures can be ignored with one or multiple --unused-fixtures-ignore-path
arguments. For example --unused-fixtures-ignore-path=venv
will ignore all fixtures defined in the venv
folder.
Ignoring specific fixtures from report
Sometimes there will be fixture which are unused on purpose, for example when used in tests which are skipped by default. A decorator is provided for ignoring fixtures from the unused report. See the example for usage:
import pytest
from pytest_unused_fixtures import ignore_unused_fixture
@pytest.fixture
@ignore_unused_fixture
def ignored_fixture():
pass
Development
Poetry (dependencies) and pre-commit (coding standards) are required for development. Ther are some tests, obviously written in pytest.
$ poetry install
$ pre-commit install
$ pytest tests
Thanks
Many thanks to
- pytest-deadfixtures for inspiration for this project
- pytest-durations for inspirations in parts of the implementation
Changelog
0.1.0 (Jun 14, 2023)
- First Release
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_unused_fixtures-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26ee14eaba9e0e161444b9694efb2469e7699574a295973952fc052d47893dfc |
|
MD5 | 2a5c92abacc9ac79b66bef1c5602de5b |
|
BLAKE2b-256 | 71abdc46f991db836da1497270d59a7a1a76dc507f3b5cfe1d46cd781e4b74a8 |
Hashes for pytest_unused_fixtures-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8320d7676bcf4f8560bfd9f59b6ad4ff9861ca4ac7da3e22e92c9a734797a40a |
|
MD5 | 12face1bef5d4a9650e1d3bedb14b7db |
|
BLAKE2b-256 | 9212054739a5e99fd38c7153f20ac87b0f286fa5cf69a5ec95ab6ffe4dccd211 |