pytest-deadfixtures

3.1.0 · active · verified Mon Apr 13

pytest-deadfixtures is a simple plugin for pytest that helps identify unused or duplicated fixtures within your test suite. It aids in improving code quality by highlighting fixtures that are no longer needed or could be refactored. The current version is 3.1.0, and the library appears to be actively maintained with a consistent release cadence.

Warnings

Install

Imports

Quickstart

To use `pytest-deadfixtures`, install the plugin and then run pytest with the `--dead-fixtures` command-line option. The plugin will analyze your test suite and report any fixtures it identifies as unused. You can optionally use `--dup-fixtures` to find duplicated fixtures or `--show-ignored-fixtures` to list fixtures that have been explicitly ignored. The `deadfixtures_ignore` decorator can be applied to fixtures you intend to leave unused.

import pytest
from pytest_deadfixtures import deadfixtures_ignore

@pytest.fixture
def used_fixture():
    return "I am used"

@pytest.fixture
def unused_fixture():
    """This fixture is intentionally unused for demonstration."""
    return "I am not used"

@pytest.fixture
@deadfixtures_ignore
def ignored_fixture():
    """This fixture will be explicitly ignored by the plugin."""
    return "I am ignored"

def test_example(used_fixture):
    assert used_fixture == "I am used"

# To run this example and see the unused fixture report, save it as a Python file (e.g., test_fixtures.py)
# and execute from your terminal:
# pytest --dead-fixtures --show-ignored-fixtures -v test_fixtures.py

view raw JSON →