Skip to main content

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

Options

Option Name Type Description
--unused-fixtures switch Enable plugin
--unused-fixtures-ignore-path string* Ignore paths for consideration of unused fixtures
--unused-fixtures-context array<string> Only consider fixtures missing if defined in these directories
--unused-fixtures-fail-when-present switch Fail pytest session if unused fixtures are present

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.

Alternatively, you can limit the scope in which the plugin looks for unused fixtures to a specific directory or directories. For example:

Limit scope to one directory This example will only display unused fixtures that were defined in the tests folder

pytest tests --unused-fixtures --unused-fixtures-context tests

Limit scope to multiple directories This example will only display unused fixtures that were defined in the directory1 and directory2/sub-directory folders

pytest tests --unused-fixtures --unused-fixtures-context directory1 directory2/sub-directory

Fail test session By default, when you use the --unused-fixtures switch, the plugin will exit with the same exit code pytest would have used if running without the plugin. Add the switch --unused-fixtures-fail-when-present and the pytest session will return a non-zero exit code if there are unused fixtures.

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

Alternatively, if you prefer module imports:

import pytest
import pytest_unused_fixtures

@pytest.fixture
@pytest_unused_fixtures.ignore
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

Changelog

0.3.1 (Dec 23, 2025)

  • Default available_fixtures to an empty set (#28)

0.3.0 (Dec 2, 2025)

  • Allow decorating fixtures with ignore_unused_fixture (#24)

0.2.1 (Nov 10, 2025)

  • Support Python 3.14
  • Drop support for 3.9

0.2.0 (Mar 15, 2025)

  • Test only on Pytest 8
  • Add --unused-fixtures-context
  • Add --unused-fixtures-fail-when-present
  • Support Python 3.13

0.1.5 (Apr 8, 2024)

  • Support Pytest 8

0.1.4 (Aug 8, 2023)

  • Bump versions, add CI

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

Release files for pytest-unused-fixtures 0.3.1

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-unused-fixtures 0.3.1
File Size Uploaded
pytest_unused_fixtures-0.3.1.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-unused-fixtures 0.3.1
File Interpreter ABI Platform
pytest_unused_fixtures-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / pytest_unused_fixtures-0.3.1.tar.gz

Download URL pytest_unused_fixtures-0.3.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e7102edf1f2b7d977218fb282bfd1b8879415747e17ef0e9f78a29dcb31cf3a6
BLAKE2b-256 checksum
How to use checksums
2312cd20cc256ef8d7dbc206d3acb3dd99816dafbe5356bed3de0722ff69bc39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 23, 2025.

Transparency log

Release files / pytest_unused_fixtures-0.3.1-py3-none-any.whl

Download URL pytest_unused_fixtures-0.3.1-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5455f970aadbebd527930fa767111aba5f484b6c514ac5a37f830669a16832bd
BLAKE2b-256 checksum
How to use checksums
14ddd5bb101ecae4abbe33a256cbca62c5575ad36eb074408f221a053b83f3d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 23, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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