python coverage.py:排除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1559424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
coverage.py: exclude files
提问by flybywire
How do I exclude entire files from coverage.pyreports?
如何从coverage.py报告中排除整个文件?
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?
根据文档,您可以通过匹配行来排除代码。我想排除整个文件,以便报告不包含 3rd 方库。我错过了什么吗?可以做到吗?
回答by Ned Batchelder
You can omit modules with the --omit flag. It takes a comma-separated list of path prefixes. So for example:
您可以使用 --omit 标志省略模块。它需要一个逗号分隔的路径前缀列表。例如:
coverage run my_program.py
coverage report --omit=path/to/3rdparty
回答by Yogesh K
Omitting some files worked for me using coverage API. Well it is the same kind what Ned suggested.
使用覆盖率 API 省略一些对我有用的文件。嗯,这与 Ned 建议的相同。
Here it is how I did it:
这是我如何做到的:
cov = coverage.coverage(omit='/usr/lib/python2.6/site-packages/*')
cov = coverage.coverage(omit='/usr/lib/python2.6/site-packages/*')
回答by Florian Brucker
In addition to the options in the other answers, you can also configure the ignored files via setup.cfg
:
除了其他答案中的选项外,您还可以通过setup.cfg
以下方式配置忽略的文件:
[coverage:run]
omit =
some/directory/*
debug_*.py
See the documentationfor details.
有关详细信息,请参阅文档。