Question

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"?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top