タイトルは釣りです。
pytest で pep8 のテストを行う pytest-pep8 プラグインがあります。次のようなサンプルコードを用意します。
(test)$ vi sample.py
x=3
class A(object): pass
def f(x):
return x
このサンプルコードを pep8 でチェックすると、たくさんのエラーが出ます。
(test)$ pep8 -r sample.py
sample.py:1:2: E225 missing whitespace around operator
sample.py:2:1: E302 expected 2 blank lines, found 0
sample.py:2:16: E701 multiple statements on one line (colon)
sample.py:4:1: E302 expected 2 blank lines, found 1
sample.py:6:1: W391 blank line at end of file
同じように pytest-pep8 0.7 で実行します。
(test)$ py.test --version
This is py.test version 2.2.4, imported from /Users/t2y/.virtualenvs/test/lib/python2.7/site-packages/pytest.pyc
setuptools registered plugins:
pytest-pep8-0.7 at /Users/t2y/.virtualenvs/test/lib/python2.7/site-packages/pytest_pep8.pyc
(test)$ py.test --pep8 sample.py
========================= test session starts ==========================
platform darwin -- Python 2.7.3 -- pytest-2.2.4
pep8 ignore opts: (performing all available checks)
collected 1 items
sample.py F
=============================== FAILURES ===============================
______________________________ PEP8-check ______________________________
/Users/t2y/tmp/t/sample.py:1:2: E225 missing whitespace around operator
x=3
^
/Users/t2y/tmp/t/sample.py:2:1: E302 expected 2 blank lines, found 0
class A(object): pass
^
/Users/t2y/tmp/t/sample.py:2:16: E701 multiple statements on one line (colon)
class A(object): pass
^
/Users/t2y/tmp/t/sample.py:4:1: E302 expected 2 blank lines, found 1
def f(x):
^
/Users/t2y/tmp/t/sample.py:6:1: W391 blank line at end of file
^
======================= 1 failed in 0.01 seconds =======================
全く同じエラーが出ます。何もオプションを付けずに使っている分には問題ありません。
ここで pytest.ini に PEP8 のコーディングスタイルを無視するオプションを追加します。
(test)$ vi pytest.ini
[pytest]
pep8ignore = E302 E701
E302 と E701 のエラーだけを無視して、E225 と W391 のエラーは出力されるはずなのですが、、、
(test)$ py.test --pep8 sample.py
========================= test session starts ==========================
platform darwin -- Python 2.7.3 -- pytest-2.2.4
pep8 ignore opts: E302 E701
collected 1 items
sample.py .
======================= 1 passed in 0.01 seconds =======================
pytest-pep8 0.7 では、テストが成功してしまいます。これは pep8ignore に設定した無視したいエラー総数が、PEP8 違反としたいエラー総数よりも多いときにテストが成功してしまう不具合がありました。
pytest-pep8 0.8 ではこの不具合が修正されています。
(test)$ pip install pytest-pep8==0.8
(test)$ py.test --pep8 sample.py
========================= test session starts ==========================
platform darwin -- Python 2.7.3 -- pytest-2.2.4
pep8 ignore opts: E302 E701
collected 1 items
sample.py F
=============================== FAILURES ===============================
______________________________ PEP8-check ______________________________
/Users/t2y/tmp/t/sample.py:1:2: E225 missing whitespace around operator
x=3
^
/Users/t2y/tmp/t/sample.py:6:1: W391 blank line at end of file
^
======================= 1 failed in 0.01 seconds =======================
今度は正しく E225 と W391 のエラーが検出されましたね。
おそらく pep8ignore オプションを設定していると、1つ2つのエラーを見逃してしまっている可能性があります。あるとき pytest-pep8 をアップグレードしたら、ソースいじってないのにエラーが出るようになったと不思議に思うことがあるかもしれません。
参考までに修正された内容です。
もしかしたら、あるときに pep8 の API 仕様が変わったのかな?詳しく調べてはいません。