gpt4 book ai didi

Python 覆盖率报告仅覆盖测试文件

转载 作者:行者123 更新时间:2023-12-04 16:45:50 25 4
gpt4 key购买 nike

我对开源项目的贡献还很陌生,我正在尝试获取一些覆盖率报告,以便我可以找出需要更多/更好测试的内容。但是,我无法完全覆盖测试。这是给 pytorch

例如,假设我想获得 test_indexing_py 的覆盖率报告。

我运行命令:

pytest test_indexing.py --cov=../ --cov-report=html

结果是这样:
================================================= test session starts =================================================
platform win32 -- Python 3.7.4, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
rootdir: C:\Projects\pytorch
plugins: hypothesis-5.4.1, arraydiff-0.3, cov-2.8.1, doctestplus-0.4.0, openfiles-0.4.0, remotedata-0.3.2
collected 62 items

test_indexing.py ............................s................................. [100%]

----------- coverage: platform win32, python 3.7.4-final-0 -----------
Coverage HTML written to dir htmlcov


=========================================== 61 passed, 1 skipped in 50.43s ============================================

好的,看起来测试运行了。现在,当我查看 html coverage report 时,我只得到测试文件的覆盖率,而不是测试的类(测试按覆盖率排序)。

如您所见,我只获得了 test_indexing.py 的覆盖范围。我如何获得完整的覆盖报告,包括测试的类?

任何指导将不胜感激。

最佳答案

我认为这是因为您要求检查测试运行目录的覆盖率,即 test_indexing.py是。

更好的方法是从根目录本身运行测试,而不是测试目录,它具有读取配置文件等几个优点。

关于您的问题,请尝试从根目录运行测试并尝试

  • pytest path/to/test/ --cov --cov-report=html
  • 关于Python 覆盖率报告仅覆盖测试文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60658028/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com