문제

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

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top