The Python Oracle

pylint complains on py.test: "Module 'pytest' has no 'raises' member"

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3

--

Chapters
00:00 Pylint Complains On Py.Test: &Quot;Module 'Pytest' Has No 'Raises' Member&Quot;
00:41 Accepted Answer Score 2
01:38 Answer 2 Score 4
01:47 Thank you

--

Full question
https://stackoverflow.com/questions/1064...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #pylint #pytest

#avk47



ANSWER 1

Score 4


You can silence this in a pylintrc file with: ignored-classes=pytest




ACCEPTED ANSWER

Score 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)