Skip to main content

A pytest plugin to list unused fixtures after a test run.

Project description

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

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.

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

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.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

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_unused_fixtures-0.1.3.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

pytest_unused_fixtures-0.1.3-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest_unused_fixtures-0.1.3.tar.gz.

File metadata

  • Download URL: pytest_unused_fixtures-0.1.3.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.0 CPython/3.10.12 Linux/6.3.8-200.fc38.x86_64

File hashes

Hashes for pytest_unused_fixtures-0.1.3.tar.gz
Algorithm Hash digest
SHA256 811b8e4f2ef12470cbe4beb2caa0ffe7637efc2f08552e878e7049bbb7e265b4
MD5 017f88735f89bb0b949abb466993bd63
BLAKE2b-256 dd6ba1403e2e1ede4ffe8fb20cf3be47a42cd97e5c30b092a30873dc9562cdbd

See more details on using hashes here.

Provenance

File details

Details for the file pytest_unused_fixtures-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_unused_fixtures-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 da39ba6860eb7c524caa76eb73df542812f1da133f5659baca6d1f086f2f45db
MD5 84f74630aab8f3a3fe09476b529c0620
BLAKE2b-256 18aa1a4fcb70281ec1170e9affaf9ea4e1ecca5067d4c25528057463bf22b23c

See more details on using hashes here.

Provenance

Supported by

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