【发布时间】:2020-03-12 16:16:14
【问题描述】:
我对为开源项目做出贡献还很陌生,我正在尝试获取一些覆盖率报告,以便找出需要更多/更好测试的内容。但是,我无法全面覆盖测试。这是给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 的报道。如何获得包含测试类的完整覆盖率报告?
任何指导将不胜感激。
【问题讨论】:
-
传递包名而不是路径,例如
pytest ... --cov=pytorch -
@hoefling 谢谢。这是我使用的特定命令:
pytest test_indexing.py --cov-report html --cov=torch
标签: python unit-testing pytorch pytest code-coverage