Registry / testing / pytest-flake8

pytest-flake8

JSON →
library1.3.0pypypiunverified

pytest-flake8 is a pytest plugin that integrates flake8 into your test suite to check Python code against PEP8, PyFlakes, and McCabe complexity. As of version 1.3.0, it is actively maintained by coherent-oss with regular releases and supports Python >=3.9.

pip install pytest-flake8
INSTALL
IMPORT
SIG · PYTEST-FLAKE8
P
pytest-flake8
testingpythonv1.3.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

After installation, run `pytest --flake8` to execute flake8 checks on all discovered Python files. Configuration for pytest-flake8 specific options (e.g., `flake8-max-line-length` or `flake8-ignore`) should be placed in your `setup.cfg` under the `[tool:pytest]` section or in `pyproject.toml` under `[tool.pytest.ini_options]` if using pytest >= 6.0.

# content of your_module.py def long_line_function(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12): pass # content of setup.cfg or pyproject.toml # For setup.cfg: # [tool:pytest] # flake8-max-line-length = 79 # For pyproject.toml (requires pytest>=6.0): # [tool.pytest.ini_options] # flake8-max-line-length = 79 # Run pytest with flake8 checks # pytest --flake8 your_module.py
Debug
Known issues
breakingpytest-flake8 has experienced breaking changes with various pytest versions. Specifically, changes in pytest 3.5.0 (JUnit XML output) and pytest 4.1.0 (deprecated functions) caused incompatibilities in older pytest-flake8 versions. Additionally, Python 2, 3.5, and 3.6 are no longer supported since pytest-flake8 v1.1.0.
fix
Consult pytest-flake8's release history and pytest's changelog for compatible versions, or upgrade to the latest versions of both for Python 3.9+.
affects: <1.1.0 for Python compatibility, specific older versions for pytest compatibility
gotchaBy default, pytest-flake8 caches clean results. This can lead to all flake8 tests appearing to 'skip' if no relevant files have changed, which might be confusing during development.
fix
To force a re-evaluation of all files and clear the cache, run `pytest --cache-clear --flake8`.
affects: All versions
gotchapytest-flake8 does not provide a direct mechanism to configure *other* flake8 plugins (e.g., flake8-bugbear, flake8-docstrings) through its own pytest configuration options.
fix
Configure additional flake8 plugins using standard flake8 configuration files (e.g., `.flake8`, a `[flake8]` section in `setup.cfg`, or `[tool.flake8]` in `pyproject.toml`).
affects: All versions
gotchaRunning pytest-flake8 concurrently with pytest-cov (for code coverage) can significantly increase test execution time.
fix
For optimal performance, consider running flake8 checks as a separate step in your CI pipeline or development workflow, rather than integrated directly with pytest for coverage runs.
affects: All versions
gotchapytest-flake8-specific options (e.g., `flake8-ignore`, `flake8-max-line-length`) are read from the `[tool:pytest]` section in `setup.cfg` or the `[pytest]` or `[tool.pytest.ini_options]` sections in `pyproject.toml`. Placing these options directly under a generic `[flake8]` section may not be honored by the plugin.
fix
Ensure pytest-flake8 configuration is correctly nested under the appropriate pytest configuration section in your `setup.cfg` or `pyproject.toml`.
affects: All versions
Errors
Common errors & fixes
pytest: error: unrecognized arguments: --flake8
The pytest-flake8 plugin is not installed or not active in the Python environment where pytest is being executed.
fix
Install the plugin using `pip install pytest-flake8` in your active Python environment.
ERROR: pytest-flake8 requires flake8. Please install it with 'pip install flake8'.
The 'flake8' package, a required dependency for pytest-flake8, is missing from the current Python environment.
fix
Install the missing dependency by running `pip install flake8`.
E501 line too long (88 > 79)
pytest-flake8 is reporting a standard flake8 violation (e.g., line length or specific error code), and you haven't configured flake8 to ignore it or adjust its limits.
fix
Configure flake8 options in your `pytest.ini` or `pyproject.toml` file under the `[flake8]` section, for example: `[flake8]
ignore = E501, W292
max-line-length = 100`.
ERROR: Package 'pytest-flake8' requires a different Python: X.Y.Z is not in '>=3.9'
The installed Python version (X.Y.Z) is older than the minimum required version (3.9) for pytest-flake8 version 1.3.0.
fix
Upgrade your Python environment to version 3.9 or newer, or use an older version of pytest-flake8 that supports your current Python version.
Upgrade
Version history
1.3.0latest on PyPI · released Nov 9, 2024
Audit
Dependencies
pytestrequiredCore testing framework, required for the plugin to function.
flake8requiredThe static code analysis tool that this plugin integrates.
pythonrequiredRequires Python >=3.9
Agent activity
5 hits · last 30 days
node
4
Resources
pytest-flake8 — pip install pytest-flake8 · libregistry