【问题标题】:Coverage "No source for code" with pytest使用 pytest 覆盖“无代码源”
【发布时间】:2022-06-17 22:35:20
【问题描述】:

我正在尝试通过我的 pytest 测试来衡量代码覆盖率。我尝试遵循覆盖率的快速入门指南 (https://coverage.readthedocs.io/en/6.4.1/)

当我使用以下命令运行测试时,一切似乎都很好

coverage run -m pytest tests/
===================================== test session starts ======================================
platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/arnaud/Documents/Github/gotcha
collected 4 items                                                                              

tests/preprocessing/test_preprocessing.py ....                                           [100%]

====================================== 4 passed in 0.30s =======================================

但是,当我尝试使用其中任一命令访问报告时,

coverage report

coverage html

我收到以下消息:

No source for code: '<project_directory>/config-3.py'.

到目前为止,我还没有找到解决这个问题的合适方法

【问题讨论】:

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


    【解决方案1】:

    使用命令可以忽略错误

    coverage html -i
    

    解决了我的问题

    【讨论】:

      猜你喜欢
      • 2023-02-02
      • 1970-01-01
      • 2022-11-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      相关资源
      最近更新 更多