Skip to main content

pytest plugin for efficiently checking PEP8 compliance

Version PyPi CI Issues PRs

Download stats

Usage

Install by running the command:

pip install pytest-flake8-v2

After installing it, when you run tests with the option:

pytest --flake8

every file ending in .py will be discovered and checked with flake8.

Note

If optional flake8 plugins are installed, those will be used automatically. You can configure them via flake8 section in the pytest.ini file or with a standalone flake8 config file (the path can be configure via flake8-pytest pytest config parameter).

Warning

Running flake8 tests on your project is likely to cause a number of issues. The plugin allows one to configure on a per-project and per-file basis which errors or warnings to ignore, see flake8-ignore.

Configuring FLAKE8 options per project and file

Flake8 config file

Flake8-pytest automatically sets flake8 config file to match pytest config file path. This means that you can configure flake8 by adding a [flake8] section to the pytests' config.

#
[pytest]
markers = flake8

[flake8]
max-line-length = 71
ignore = W292 ; ignore "no newline at end of file"

You can override this default by using flake8-config parameter

[pytest]
flake8-config = ./pytest.ini

If path relative, than it is treated as relative to pytests' config file.

Extra CLI parameters

You can set flake8-cli-arguments pytest config if you want to pass additional CLI arguments to the flake8. E.g.

[pytest]
flake8-cli-arguments = --max-line-length 71

Will cause for all flake8 tests to be called with an equivalent of flake8 --max-line-length 71 <target_file.py> command.

Misc

You may configure flake8-checking options for your project by adding an flake8-ignore entry to your setup.cfg or tox.ini file like this:

# content of setup.cfg
[tool:pytest]
flake8-ignore = E201 E231

This would globally prevent complaints about two whitespace issues. Rerunning with the above example will now look better:

$ pytest -q  --flake8
collecting ... collected 1 items
.
1 passed in 0.01 seconds

If you have some files where you want to specifically ignore some errors or warnings you can start a flake8-ignore line with a glob-pattern and a space-separated list of codes:

# content of setup.cfg
[tool:pytest]
flake8-ignore = 
    *.py E201
    doc/conf.py ALL

So if you have a conf.py like this:

# content of doc/conf.py

func (  [1,2,3]) #this line lots PEP8 errors :)

then running again with the previous example will show a single failure and it will ignore doc/conf.py alltogether:

$ pytest --flake8 -v # verbose shows what is ignored
======================================= test session starts ========================================
platform darwin -- Python 2.7.6 -- py-1.4.26 -- pytest-2.7.0 -- /Users/tholo/Source/pytest/bin/python
cachedir: /Users/tholo/Source/pytest/src/verify/.cache
rootdir: /Users/tholo/Source/angular/src/verify, inifile: setup.cfg
plugins: flake8, cache
collected 1 items

myfile.py PASSED

========================================= 1 passed in 0.00 seconds =========================================

Note that doc/conf.py was not considered or imported.

FAQs

All the flake8 tests are skipping!

This is by design. Clean flake8 results are cached and, unless the file is modified, not tested again.

You can run with pytest --cache-clear --flake8 to override this.

Notes

The repository of this plugin is at https://github.com/VRGhost/pytest-flake8

For more info on pytest see http://pytest.org

The code is partially based on Ronny Pfannschmidt's pytest-codecheckers plugin.

Metadata

Release files for pytest-flake8-v2 1.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-flake8-v2 1.2.3
File Size Uploaded
pytest-flake8-v2-1.2.3.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-flake8-v2 1.2.3
File Interpreter ABI Platform
pytest_flake8_v2-1.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 21.6 kB

Release files / pytest-flake8-v2-1.2.3.tar.gz

Download URL pytest-flake8-v2-1.2.3.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9faa758da09617dbbeb735848867f5d919ba15cf16d84e76b4d5b69f5e3e22b7
BLAKE2b-256 checksum
How to use checksums
a63ede433fcab7032186c902895282f9dad409a3820ef2fb73d28252a6f6eda0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release files / pytest_flake8_v2-1.2.3-py3-none-any.whl

Download URL pytest_flake8_v2-1.2.3-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c39d708bf37059ef1d56681431ef86519fdd36c0cc81652c88b4e721da08a530
BLAKE2b-256 checksum
How to use checksums
66775fc01d522631ebb1467dd8c8563c12bb0a1e1ce1aeb43daf9e52b7c667a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release history Release notifications | RSS feed

This release

1.2.3 This release

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page