python - 从 python 的覆盖范围中排除单元测试

标签 python unit-testing coverage.py python-coverage

我刚开始使用 coverage.py .我使用 coverage run unit_tests.py 来运行我的测试。然后我使用生成以下覆盖率摘要的覆盖率报告:

Name         Stmts   Miss  Cover
--------------------------------
cardnames       28      0   100%
dominion       458    210    54%
unit_tests     181      0   100%
--------------------------------
TOTAL          667    210    69%

除了包含我试图在 unit_tests.py 中测试的 cardnames.pydominion.py 之外,覆盖率报告还包含 unit_tests.py 文件本身。 (在覆盖率计算中)。如何从报告中排除该文件?

最佳答案

来自他们的 documentation :

You can further fine-tune coverage.py’s attention with the --include and --omit switches (or [run] include and [run] omit configuration values). --include is a list of filename patterns. If specified, only files matching those patterns will be measured. --omit is also a list of filename patterns, specifying files not to measure.

因此,从臀部编写脚本,语法类似于 coverage run --source=<files to be included> --omit=unit_tests.py unit_tests.py .

关于python - 从 python 的覆盖范围中排除单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28405664/

相关文章:

c# - RhinoMocks stub 具有简化的实现,尝试方法模式

python - 当条件为真时,Pandas 将数据帧拆分为多个

Python:有效替换子字符串

unit-testing - 如何使用 Symfony 在 serviceTest 中模拟 EntityManager?

unit-testing - 在Grails中通过BuildConfig.groovy使用依赖关系解析时,如何有效地进行单元测试?

Python覆盖率看不到配置文件

python - 合并分支覆盖文件python

python - 是否可以在 Python 中进行代码覆盖断言?

python - Django对象扩展/一对一关系问题

python - 根据另一列更改列的值