Pytest 2.5.2 covers reports of missing lines that should have been processed.

I have a small Python pet project for which I want to make coverage reports. When i started

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

This shows me a significant number of lines missing in coverage. These are mainly import and class / method definitions. Screen shot

I am sure that all these lines are processed in my unit tests, and lines 19 and 31-35 confirm this.

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

+6
source share
2 answers

A common reason is that the conftest.py module imports the early module that needs to be measured. Test configuration must be evaluated prior to naturarely tests. This dependency can sometimes not be easily removed. This is why many answers recommend ways to work around the pytest-cov extension:
answer 1 and answer 2

+2
source

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

The coverage report is correct because all of these lines are imported before the test begins.


I am sure that all these lines are processed in my unit tests, and lines 19 and 31-35 confirm this.

All objects of the first class are evaluated at loading, including import, globals, function 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 this does not mean that the rest.

+1
source

All Articles