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

2024-05-15 22:54:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉使用coverage.py。我使用coverage run unit_tests.py来运行我的测试。然后我使用coverage report,它生成了以下覆盖率摘要:

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

除了包括cardnames.py和{}之外,我正在单元内测试_测试.py,覆盖率报告还包括unit_tests.py文件本身。(在覆盖率计算中)。如何从报告中排除此文件?在


Tags: 文件runnamepyreport报告coverage覆盖率
1条回答
网友
1楼 · 发布于 2024-05-15 22:54:07

从他们的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.

所以,从hip开始编写脚本,语法应该是coverage run source=<files to be included> omit=unit_tests.py unit_tests.py。在

相关问题 更多 >