Skip to main content

A simple plugin to list unused fixtures in pytest

Project description

Donate See Build Status on Travis CI

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-deadfixtures-2.0.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_deadfixtures-2.0.1-py2.py3-none-any.whl (4.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest-deadfixtures-2.0.1.tar.gz.

File metadata

File hashes

Hashes for pytest-deadfixtures-2.0.1.tar.gz
Algorithm Hash digest
SHA256 d436f4c6d2d9fb6977eb6aed6e3f7120ee2bd4fdc117f699cf5c296ddf2a3d95
MD5 0955fd5586acb91e6dec377f09058ec3
BLAKE2b-256 efc325c720b5bf1cc596b59bb9a42ad3b37877d889b51b6e0b192f31bb9e4d17

See more details on using hashes here.

File details

Details for the file pytest_deadfixtures-2.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_deadfixtures-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 cac3975fa3ac27d6e58f39ae18cbd5bc58396d8319a4c4f603a4220dd6eb27d9
MD5 b9e002df6bda3304fe8b42ac7dfc41fc
BLAKE2b-256 cc65b611b0604a02ec5ef14e3c8b3a379eac07d6671a3cbdd89461962b79665e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page