This plugin enables you to run vulture (https://pypi.org/project/vulture/) alongside pytest, allowing for dead code detection during your testing process.
To integrate vulture with pytest and find dead code, use the following commands:
Basic Usage Run vulture with pytest to check for dead code:
pytest --vulture
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
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
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"
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
This code depends on vulture
If you want to help development, there is overview documentation in DEVELOPMENT.rst.
If you encounter any problems, please file an issue along with a detailed description.
- Add pyproject.toml support for parameters
- Uses vulture with pytest (tested with python 3.7 3.8 and 3.9, with vulture==2.3 and pytest 7.x)
- stable Gatewatcher internal use only
- unstable Gatewatcher internal use only