coverage.py:排除文件
如何从 coverage.py 报告中排除整个文件?
根据文档,您可以通过匹配行来排除代码。我想排除整个文件,以便报告不包含第三方库。我错过了什么吗?能做到吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 --omit 标志省略模块。它采用逗号分隔的路径前缀列表。例如:
You can omit modules with the --omit flag. It takes a comma-separated list of path prefixes. So for example:
除了其他答案中的选项之外,您还可以通过 setup.cfg 配置忽略的文件:
请参阅文档 了解详细信息。
In addition to the options in the other answers, you can also configure the ignored files via
setup.cfg
:See the documentation for details.
使用覆盖 API 省略一些文件对我有用。
嗯,这与内德的建议是一样的。
这就是我的做法:
cov =coverage.coverage(omit='/usr/lib/python2.6/site-packages/*')
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/*')
使用 pyproject.toml
With
pyproject.toml
创建一个新文件
.coveragerc
并添加以下行Create a new file
.coveragerc
and add the following lines