5

次のコードを使用します。

import pytest
def test_a():
    with pytest.raises(Exception):
        1/0

その上で pylint を実行すると、「レイズ」がモジュール pytest のメンバーではないことを訴えます。

E:  3,9:test_a: Module 'pytest' has no 'raises' member

これは明らかに真実ではありません。なぜpylintがそのような間違いを犯しているのか、何か考えはありますか? これは既知のバグですか?

py.test バージョン:

> py.test --version
This is py.test version 2.2.3, imported from C:\Python27\lib\site-packages\pytest.pyc

PyLint バージョン:

> pylint --version
No config file found, using default configuration
pylint 0.25.1,
astng 0.23.1, common 0.57.1
Python 2.7.2 (default, Jun 24 2011, 12:22:14) [MSC v.1500 64 bit (AMD64)]
4

2 に答える 2

3

これをpylintrcファイルで次のように沈黙させることができます: ignored-classes=pytest

于 2014-02-04T17:43:33.240 に答える
2

Last time I looked pylib does some heavy dynamic in low level python stuff, such as completely redefining the import code. It is very likely that this completely baffles pylint/astng, and prevents it from getting what is inside the pytest module: pylint/astng does not import the code it analyzes, it parses it, meaning that stuff which is dynamically initialized at import time will usually go unnoticed, which in turn generates false positives such as the one you report.

From there, you face the following choices:

  • use another unittest framework, less dynamic than py.test
  • silence the warnings / errors on your test code manually
  • use another linter which is happier than pylint on py.test (I'm interested to know how pychecker / pyflakes fare on that code)
  • write the astng plugin which will help astng grok the pylib tricks and submit it as a patch to the astng maintainers (and get extra credit from that)
于 2012-05-18T10:20:24.520 に答える