pytest-unused-fixtures


Namepytest-unused-fixtures JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/mikicz/pytest-unused-fixtures
SummaryA pytest plugin to list unused fixtures after a test run.
upload_time2024-04-08 09:29:39
maintainerNone
docs_urlNone
authorMikuláš Poul
requires_python<4.0,>=3.9
licenseMIT
keywords pytest fixtures
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```shell
$ 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:

```python
import pytest
from pytest_unused_fixtures import ignore_unused_fixture

@pytest.fixture
@ignore_unused_fixture
def ignored_fixture():
    pass
```

## Development

[Poetry](https://python-poetry.org/) (dependencies) and [pre-commit](https://pre-commit.com/) (coding standards) are required for development. There are some tests, obviously written in [pytest](https://pytest.org/).

```shell
$ poetry install
$ pre-commit install
$ pytest tests
```

## Thanks

Many thanks to

 - [pytest-deadfixtures](https://github.com/jllorencetti/pytest-deadfixtures) for inspiration for this project
 - [pytest-durations](https://github.com/blake-r/pytest-durations) for inspirations in parts of the implementation

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


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mikicz/pytest-unused-fixtures",
    "name": "pytest-unused-fixtures",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "pytest, fixtures",
    "author": "Mikul\u00e1\u0161 Poul",
    "author_email": "mikulaspoul@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/35/45/780fd2e93adb2828e1ae95597283697169ba408fb24667b3849de0e169bf/pytest_unused_fixtures-0.1.5.tar.gz",
    "platform": null,
    "description": "# pytest-unused-fixtures\n\nA pytest plugin to list unused fixtures after a test run.\n\nThe 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.\n\nRunning 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.\n\n## Installation\n\n```shell\n$ pip install pytest-unused-fixtures\n```\n\n## Usage\n\nAfter installing the package, the plugin is enabled by adding the switch `--unused-fixtures`.\n\nPaths 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.\n\n### Ignoring specific fixtures from report\n\nSometimes 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:\n\n```python\nimport pytest\nfrom pytest_unused_fixtures import ignore_unused_fixture\n\n@pytest.fixture\n@ignore_unused_fixture\ndef ignored_fixture():\n    pass\n```\n\n## Development\n\n[Poetry](https://python-poetry.org/) (dependencies) and [pre-commit](https://pre-commit.com/) (coding standards) are required for development. There are some tests, obviously written in [pytest](https://pytest.org/).\n\n```shell\n$ poetry install\n$ pre-commit install\n$ pytest tests\n```\n\n## Thanks\n\nMany thanks to\n\n - [pytest-deadfixtures](https://github.com/jllorencetti/pytest-deadfixtures) for inspiration for this project\n - [pytest-durations](https://github.com/blake-r/pytest-durations) for inspirations in parts of the implementation\n\n## Changelog\n\n### 0.1.3 (Jun 30, 2023)\n\n* Print line number\n* Support Python 3.9\n\n### 0.1.2 (Jun 15, 2023)\n\n* Fix typo, add repository to PyPI\n* Update location handling with respect to showing fixture locations and ignoring paths\n\n### 0.1.1 (Jun 14, 2023)\n\n* Fix location handling\n* Add decorator for ignoring fixtures from report\n\n### 0.1.0 (Jun 14, 2023)\n\n* First Release\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A pytest plugin to list unused fixtures after a test run.",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/mikicz/pytest-unused-fixtures",
        "Repository": "https://github.com/mikicz/pytest-unused-fixtures"
    },
    "split_keywords": [
        "pytest",
        " fixtures"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0af2ef1f5e9b528390fce075e88758199648c6abc3c3d6d00385b364442c1f9",
                "md5": "723bd5ef87a13edb8c5392595b958c6a",
                "sha256": "a796fe664ed324b584fa58376c496cba623248ca42802e27153da1e3bed7f43f"
            },
            "downloads": -1,
            "filename": "pytest_unused_fixtures-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "723bd5ef87a13edb8c5392595b958c6a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 7554,
            "upload_time": "2024-04-08T09:29:38",
            "upload_time_iso_8601": "2024-04-08T09:29:38.270180Z",
            "url": "https://files.pythonhosted.org/packages/b0/af/2ef1f5e9b528390fce075e88758199648c6abc3c3d6d00385b364442c1f9/pytest_unused_fixtures-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3545780fd2e93adb2828e1ae95597283697169ba408fb24667b3849de0e169bf",
                "md5": "05bafc84fabdd3fdef3f255346decf54",
                "sha256": "40cc3f122adbb88c703f8f989e031a37966bbe284db99f4699ae9e61b5743a79"
            },
            "downloads": -1,
            "filename": "pytest_unused_fixtures-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "05bafc84fabdd3fdef3f255346decf54",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 5548,
            "upload_time": "2024-04-08T09:29:39",
            "upload_time_iso_8601": "2024-04-08T09:29:39.893315Z",
            "url": "https://files.pythonhosted.org/packages/35/45/780fd2e93adb2828e1ae95597283697169ba408fb24667b3849de0e169bf/pytest_unused_fixtures-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-08 09:29:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mikicz",
    "github_project": "pytest-unused-fixtures",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-unused-fixtures"
}
        
Elapsed time: 0.23179s