A simple plugin to list unused fixtures in pytest
Project description
A simple plugin to list unused or duplicated fixtures in a pytest suite.
Features
List unused fixtures in your tests
List duplicated fixtures
Installation
You can install “pytest-deadfixtures” via pip from PyPI:
$ pip install pytest-deadfixtures
Usage
Important
The –dead-fixtures option will not run your tests and it’s also sensible for errors in the pytest collection step. If you are using as part of you CI process the recommended way is to run it after the default test run. For example:
script: - pytest - pytest --dead-fixtures
Listing unused fixtures
Just run ‘pytest’ with an extra option ‘–dead-fixtures’:
$ pytest --dead-fixtures ============================= test session starts ============================== (hidden for brevity) 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 in 0.00 seconds =========================
Using some level of verbosity will also print the docstring of each fixture:
$ pytest --dead-fixtures -v ============================= test session starts ============================== (hidden for brevity) Hey there, I believe the following fixture(s) are not being used: Fixture name: some_fixture, location: test_write_docs_when_verbose.py:5 Blabla fixture docs ========================= no tests ran in 0.00 seconds =========================
Listing repeated fixtures
Now that you removed every unused fixture of your test suite, what if you want to go an extra mile?
An important note about this is that it uses the fixture return value to verify if two or more fixtures are equal.
This means fixtures without a truthy return value will be skipped.
You should use this as a hint only, verify that the functionality provided by both fixtures are really repeated before deleting one of them.
Just run ‘pytest’ with an extra option ‘–dup-fixtures’, unlike the ‘–dead-fixtures’ option, it’ll normally run you tests:
$ pytest --dup-fixtures ======================================================================================================================== test session starts ======================================================================================================================== (hidden for brevity) 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
Projects using it
Contributing
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit 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, please file an issue along with a detailed description.
Project details
Release history Release notifications | RSS feed
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-deadfixtures-2.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fa7c7031c3229be551a206b5128aec2d816dd7148b0d963b0086108ccaae080 |
|
MD5 | ac1b1a58075dd7be432a532db8f27716 |
|
BLAKE2b-256 | 58c8b914b49cc1ef7fe29082e819155e0171bdb3011d063dd04efebd1aaff0eb |
Hashes for pytest_deadfixtures-2.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16be27beadf0e13af06b0e89476664b03e57d0875913856e74fb35b30cbcca22 |
|
MD5 | 15d6fe50beead824365b0d4c765cf204 |
|
BLAKE2b-256 | cfc678c32e2aeb17415ef70bd3f00f600fbecfbf2dbbeecf6570d2a81f0e53ec |