Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible exclude test directories from coverage.py reports?

I'm kind of a rookie with python unit testing, and particularly coverage.py. Is it desirable to have coverage reports include the coverage of your actual test files?

Here's a screenshot of my HTML report as an example.

You can see that the report includes tests/test_credit_card. At first I was trying to omit the tests/ directory from the reports, like so:

coverage html --omit=tests/ -d tests/coverage 

I tried several variations of that command but I could not for the life of me get the tests/ excluded. After accepting defeat, I began to wonder if maybe the test files are supposed to be included in the report.

Can anyone shed some light on this?

like image 732
Kyle Fox Avatar asked Oct 27 '09 06:10

Kyle Fox


People also ask

How do you exclude a function from code coverage in Python?

You can exclude them all at once without littering your code with exclusion pragmas. If the matched line introduces a block, the entire block is excluded from reporting. Matching a def line or decorator line will exclude an entire function.

Does coverage work with Pytest?

You can use Coverage.py with both unittest and Pytest.


1 Answers

coverage html --omit="*/test*" -d tests/coverage

like image 191
user3128809 Avatar answered Sep 20 '22 19:09

user3128809