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. There 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.3 (Jun 30, 2023)
- Print line number
- Support Python 3.9
0.1.2 (Jun 15, 2023)
- Fix typo, add repository to PyPI
- Update location handling with respect to showing fixture locations and ignoring paths
0.1.1 (Jun 14, 2023)
- Fix location handling
- Add decorator for ignoring fixtures from report
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
File details
Details for the file pytest_unused_fixtures-0.1.5.tar.gz
.
File metadata
- Download URL: pytest_unused_fixtures-0.1.5.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40cc3f122adbb88c703f8f989e031a37966bbe284db99f4699ae9e61b5743a79 |
|
MD5 | 05bafc84fabdd3fdef3f255346decf54 |
|
BLAKE2b-256 | 3545780fd2e93adb2828e1ae95597283697169ba408fb24667b3849de0e169bf |
File details
Details for the file pytest_unused_fixtures-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: pytest_unused_fixtures-0.1.5-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a796fe664ed324b584fa58376c496cba623248ca42802e27153da1e3bed7f43f |
|
MD5 | 723bd5ef87a13edb8c5392595b958c6a |
|
BLAKE2b-256 | b0af2ef1f5e9b528390fce075e88758199648c6abc3c3d6d00385b364442c1f9 |