views:

297

answers:

3

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?

A: 

have a look at _should_trace in control.py

gnibbler
+5  A: 

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
Ned Batchelder
thanks Ned. How can I do it using the API?
flybywire
In the API, you provide a list of modules you want to report on, so there's not a lot of convenient control there.
Ned Batchelder
A: 

I'm trying to exclude my actual *_test.py files from being included in the HTML output. I've tried this, but it doesn't seem to work:

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

I'm brand new to coverage.py (and StackOverflow, as a matter of fact), so hopefully I'm just overlooking something simple.

Kyle Fox
--omit accepts prefixes, not patterns
flybywire