Skip to main content

pytest plugin to check FLAKE8 requirements

Project description

pytest plugin for efficiently checking PEP8 compliance

image image PyPi CI Issues PRs

Usage

Install by running the command:

pip install pytest-flake8

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. No provisions have been made for configuring these via pytest.

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-ignore}

Maximum line length can be configured for the whole project by adding a flake8-max-line-length option to your setup.cfg or tox.ini file like this:

# content of setup.cfg
[tool:pytest]
flake8-max-line-length = 99

Note that the default will be what naturally comes with flake8 (which it turn gets its default from pycodestyle).

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/tholo/pytest-flake8

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

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

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-flake8-v2-1.0.7.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_flake8_v2-1.0.7-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest-flake8-v2-1.0.7.tar.gz.

File metadata

  • Download URL: pytest-flake8-v2-1.0.7.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for pytest-flake8-v2-1.0.7.tar.gz
Algorithm Hash digest
SHA256 d438f5180e30b4e85602f96c8eea3f294beee4c689b24c4f77a24b3f8b13261c
MD5 965675789cc6dda99ff7c383d9cf0932
BLAKE2b-256 9dcd8171f30d11c4b157f24ce51af5bed1b17c7fc9da4fbc65f05502b6ccc534

See more details on using hashes here.

File details

Details for the file pytest_flake8_v2-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: pytest_flake8_v2-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for pytest_flake8_v2-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0fd5f8a1e76acc4c56735ea8da24a80bcf4020bef3c006a673f21adb23bcffb5
MD5 1a0f91d4fb9b1958755f9a5e6e10646b
BLAKE2b-256 0849d0248552962d064706e0f0ca4da39bf53e144aa4b22af625855c09e91ec7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page