Skip to main content

A pytest plugin to checks dead code with vulture

Project description

This plugin enables you to run vulture (https://pypi.org/project/vulture/) alongside pytest, allowing for dead code detection during your testing process.

Sample Usage

To integrate vulture with pytest and find dead code, use the following commands:

  1. Basic Usage Run vulture with pytest to check for dead code:

    pytest --vulture
  2. Custom Configuration Specify a custom configuration file path:

    pytest --vulture --vulture-cfg-file=/path/to/vulture.ini

    Note: By default, the tool looks for configuration files in the following order:

    • pyproject.toml

    • tox.ini

    • vulture.ini

Ignoring Vulture Messages

You can ignore specific warnings from vulture directly in the source code. Here’s how:

  • Ignore Specific Lines:

    def test_function():
        unused_variable = 42  # vulture: ignore
  • Ignore Entire Methods:

    def ignored_function():  # vulture: ignore
        pass
  • Ignore Classes:

    class IgnoredClass:  # vulture: ignore
        pass

Configuring with pyproject.toml

Here’s an example of how to configure vulture using pyproject.toml:

[tool.vulture]
# Exclude specific paths (e.g., test directories)
exclude = [
    "*/test/*",
]

# Ignore specific files in the `pytest` output (but they are still checked by `vulture`)
ignore = [
    "src/some_ignored_file.py",
]

# Ignore specific function or variable names
ignore-names = [
    "deprecated_function",
]

# Ignore decorators
ignore-decorators = [
    "@app.route",
    "@celery.task",
]

# Ignore specific types of messages (e.g., imports)
ignore-types = [
    "import",
]

# Define the source path
source-path = "src"

Configuring with .ini Config Files

Here’s an example of how to configure vulture using an .ini file:

[vulture]
exclude =
    */test/*  # Usually exclude tests as they may cover dead code

ignore =
    src/some_ignored_file.py

ignore-names =
    deprecated_function

ignore-decorators =
    @app.route
    @celery.task

ignore-types =
    attribute
    variable

Acknowledgements

This code depends on vulture

Development

If you want to help development, there is overview documentation in DEVELOPMENT.rst.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Releases

2.2.0

  • Add pyproject.toml support for parameters

2.0.2

  • Uses vulture with pytest (tested with python 3.7 3.8 and 3.9, with vulture==2.3 and pytest 7.x)

1.0.0

  • stable Gatewatcher internal use only

0.x

  • unstable Gatewatcher internal use only

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_vulture-2.2.0.tar.gz (73.9 kB view details)

Uploaded Source

Built Distribution

pytest_vulture-2.2.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file pytest_vulture-2.2.0.tar.gz.

File metadata

  • Download URL: pytest_vulture-2.2.0.tar.gz
  • Upload date:
  • Size: 73.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.15

File hashes

Hashes for pytest_vulture-2.2.0.tar.gz
Algorithm Hash digest
SHA256 d8f7e88f0f9dfe0e4b996496e87249e12b063793cf06d46f40869de30ba91242
MD5 8ea1517a6fc4e7de79a20ae138dc1604
BLAKE2b-256 0e06ebc4b39fa1021d042e08cc1ace20d7abac45d84818966688cf99c547fd74

See more details on using hashes here.

File details

Details for the file pytest_vulture-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_vulture-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4cb8009a8e3533791dcd17ca7a1f29a53a97727525acaff3b2fef7c6d3acd423
MD5 b190edcaf98992b7c439165d650451cb
BLAKE2b-256 8e09466e0536ec7c214a616c92e654a929c3130c6f369ca40d5af127e1932878

See more details on using hashes here.

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