coverage.py: exclude files

2019-03-14 06:34发布

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?

2条回答
混吃等死
2楼-- · 2019-03-14 07:08

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
查看更多
欢心
3楼-- · 2019-03-14 07:29

Omitting some files worked for me using coverage API. Well it is the same kind what Ned suggested.

Here it is how I did it:

cov = coverage.coverage(omit='/usr/lib/python2.6/site-packages/*')

查看更多
登录 后发表回答