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?
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/**/*.
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.
That exact # pragma: no cover is the hint that the part of code should be ignored by the tool -- see Excluding code from coverage .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With