【发布时间】:2021-11-11 17:06:42
【问题描述】:
我正在查看 pytest-cov 生成的 html 覆盖率报告,我想知道是否可以找到哪些测试调用了特定行(哪些测试覆盖了特定行)。
【问题讨论】:
标签: python unit-testing pytest coverage.py pytest-cov
我正在查看 pytest-cov 生成的 html 覆盖率报告,我想知道是否可以找到哪些测试调用了特定行(哪些测试覆盖了特定行)。
【问题讨论】:
标签: python unit-testing pytest coverage.py pytest-cov
Coverage.py 包含一个名为“contexts”的功能,可以很容易地使用测试名称来注释结果:https://coverage.readthedocs.io/en/latest/contexts.html
把它放在你的 .coveragerc 文件中:
[run]
dynamic_context = test_function
【讨论】:
--cov-context=test 选项,我必须将 [html] show_contexts = True 添加到 .coveragerc 以查看 html 中的上下文。