Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest 2.5.2 coverage reports missing lines which must have been processed

I have a little pet project in Python for which I want do do coverage reports. When I run

py.test -x -s MYPACKAGE --cov-report html --cov MYPACKAGE

It shows me a significant amount of lines missing from coverage. Mainly these are imports and class/method definitions. Screenshot

I am certain that all these lines are processed in my unit tests, and the lines 19 and 31-35 verify that.

Why does py.test mark all the definitions as "missing"?

like image 896
mawimawi Avatar asked Mar 03 '14 12:03

mawimawi


2 Answers

A frequent cause is that the module conftest.py imports early the module that should be measured. The test configuration should be evaluated before tests of course. That dependency can not be easily removed sometimes. That is why many answers recommend ways how to circumvent the pytest-cov extension:
answer 1 and answer 2

like image 179
hynekcer Avatar answered Oct 08 '22 00:10

hynekcer


Why does py.test mark all the definitions as "missing"?

The coverage report is correct, because all of those lines are imported before the test actually starts.


I am certain that all these lines are processed in my unit tests, and the lines 19 and 31-35 verify that.

All first-class objects are evaluated on load, including imports, globals, functions definitions with their arguments, and class definitions with their methods, attributes, and arguments.

Lines 19 and 31-35 are processed as part of the unit test, but that doesn't mean the others are.

like image 21
mhlester Avatar answered Oct 08 '22 01:10

mhlester