Skip to main content
Black 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

  • Ignore specific fixtures from analysis with @deadfixtures_ignore

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

Ignoring specific fixtures

You can use the @deadfixtures_ignore decorator to exclude specific fixtures from the analysis:

from pytest_deadfixtures import deadfixtures_ignore

@pytest.fixture
@deadfixtures_ignore
def intentionally_unused_fixture():
    """This fixture won't be reported as unused."""
    return "something"

To see which fixtures are being ignored, use the –show-ignored-fixtures option:

$ pytest --dead-fixtures --show-ignored-fixtures
============================= test session starts ==============================
(hidden for brevity)

No unused fixtures found. Great job!

Ignored fixtures (1):
Fixture name: intentionally_unused_fixture, location: conftest.py:10

========================= no tests ran in 0.00 seconds =========================

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.

Release files for pytest-deadfixtures 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-deadfixtures 3.1.0
File Size Uploaded
pytest_deadfixtures-3.1.0.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-deadfixtures 3.1.0
File Interpreter ABI Platform
pytest_deadfixtures-3.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 16.4 kB

Release files / pytest_deadfixtures-3.1.0.tar.gz

Download URL pytest_deadfixtures-3.1.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a8010e771183176fa9d918c8c49293ca5568597c8e1453ed2bbd41bcee67bde5
BLAKE2b-256 checksum
How to use checksums
7bb56fc6a3096e5bc3124c61af17c53d09290a5bfbca51fb8b94068d1e770d0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / pytest_deadfixtures-3.1.0-py2.py3-none-any.whl

Download URL pytest_deadfixtures-3.1.0-py2.py3-none-any.whl
Size 7.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
898ba131c7472bd05551b73e2b99a51898fc3b8255c0589cf8b3c3c804e8f502
BLAKE2b-256 checksum
How to use checksums
fbd067f83859706d11717498e1ef5e75f1c61835fd972c902f5bc9cbd9cb5659
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

3.1.0 This release

2 release files

3.0.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page