Package: pytest-flake8-v2
pytest plugin for efficiently checking PEP8 complianceUsageInstall by running the command:pip install pytest-flake8-v2After installing it, when you run tests with the option:pytest --flake8every file ending in.pywill be discovered and checked with flake8.NoteIf optional flake8 plugins are installed, those will be used
automatically. You can configure them viaflake8section in thepytest.inifile
or with a standalone flake8 config file (the path can be configure viaflake8-pytestpytest config parameter).WarningRunning 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, seeflake8-ignore.Configuring FLAKE8 options per project and fileFlake8 config fileFlake8-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 usingflake8-configparameter[pytest]
flake8-config = ./pytest.iniIf path relative, than it is treated as relative to pytests' config file.Extra CLI parametersYou can setflake8-cli-argumentspytest config if you want to pass additional CLI arguments to the flake8.
E.g.[pytest]
flake8-cli-arguments = --max-line-length 71Will cause for all flake8 tests to be called with an equivalent offlake8 --max-line-length 71 <target_file.py>command.MiscYou may configure flake8-checking options for your project by adding anflake8-ignoreentry to yoursetup.cfgortox.inifile like this:# content of setup.cfg
[tool:pytest]
flake8-ignore = E201 E231This 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 secondsIf 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 ALLSo 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.FAQsAll 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 withpytest --cache-clear --flake8to override this.NotesThe repository of this plugin is athttps://github.com/VRGhost/pytest-flake8For more info onpytestseehttp://pytest.orgThe code is partially based on Ronny Pfannschmidt'spytest-codecheckersplugin.