blob: d328e6f1fc897ddf9b47594f194b9be3e4e5806f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
pytest plugin for efficiently checking PEP8 compliance
======================================================
.. image:: https://img.shields.io/pypi/v/pytest-flake8.svg
:target: https://pypi.python.org/pypi/pytest-flake8
.. image:: https://img.shields.io/pypi/pyversions/pytest-flake8.svg
:target: https://pypi.python.org/pypi/pytest-flake8
.. image:: https://img.shields.io/pypi/implementation/pytest-flake8.svg
:target: https://pypi.python.org/pypi/pytest-flake8
.. image:: https://img.shields.io/pypi/status/pytest-flake8.svg
:target: https://pypi.python.org/pypi/pytest-flake8
.. image:: https://travis-ci.org/tholo/pytest-flake8.svg?branch=master
:target: https://travis-ci.org/tholo/pytest-flake8
.. image:: https://img.shields.io/github/issues/tholo/pytest-flake8.svg
:target: https://github.com/tholo/pytest-flake8/issues
.. image:: https://img.shields.io/github/issues-pr/tholo/pytest-flake8.svg
:target: https://github.com/tholo/pytest-flake8/pulls
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_.
.. _flake8-ignore:
Configuring FLAKE8 options per project and file
-----------------------------------------------
Maximum line length and maximum doc line length can be configured for the
whole project by adding a ``flake8-max-line-length`` option and
``flake8-max-doc-length`` to your ``setup.cfg`` or ``tox.ini`` file like
this::
# content of setup.cfg
[tool:pytest]
flake8-max-line-length = 99
flake8-max-doc-length = 74
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 altogether::
$ 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.
.. _`pytest`: http://pytest.org
.. _`flake8`: https://pypi.python.org/pypi/flake8
.. _`pycodestyle`: https://pypi.python.org/pypi/pycodestyle
.. _`pytest-codecheckers`: https://pypi.python.org/pypi/pytest-codecheckers
|