【问题标题】:Using pytest coverage, is there a way to tell which tests invoked a particular statement?使用 pytest 覆盖率,有没有办法判断哪些测试调用了特定语句?
【发布时间】:2021-11-11 17:06:42
【问题描述】:

我正在查看 pytest-cov 生成的 html 覆盖率报告,我想知道是否可以找到哪些测试调用了特定行(哪些测试覆盖了特定行)。

【问题讨论】:

    标签: python unit-testing pytest coverage.py pytest-cov


    【解决方案1】:

    Coverage.py 包含一个名为“contexts”的功能,可以很容易地使用测试名称来注释结果:https://coverage.readthedocs.io/en/latest/contexts.html

    把它放在你的 .coveragerc 文件中:

    [run]
    dynamic_context = test_function
    

    【讨论】:

    • 我在 pytest 中使用了 --cov-context=test 选项,我必须将 [html] show_contexts = True 添加到 .coveragerc 以查看 html 中的上下文。
    猜你喜欢
    • 1970-01-01
    • 2016-07-27
    • 2020-05-25
    • 2010-12-30
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多