Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coverage.py: exclude files

How do I exclude entire files from coverage.py reports?

According to the documentation you can exclude code by matching lines. I want to exclude entire files, so that the reports don't include 3rd party libraries. Am I missing something? Can it be done?

like image 201
flybywire Avatar asked Oct 13 '09 10:10

flybywire


People also ask

How do I exclude files from jest coverage?

To ignore a file pattern for Jest code coverage, we can add the option in the Jest config. to calculate the code coverage from the paths that match patterns listed in collectCoverageFrom that don't have the exclamation mark before it. As a result, we see code coverage calculated from the src/**/*.

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.

What is Pragma no cover?

That exact # pragma: no cover is the hint that the part of code should be ignored by the tool -- see Excluding code from coverage .


1 Answers

You can omit modules with the --omit flag. It takes a comma-separated list of path prefixes. So for example:

coverage run my_program.py coverage report --omit=path/to/3rdparty 
like image 167
Ned Batchelder Avatar answered Sep 28 '22 21:09

Ned Batchelder