如果您没有指定--cov=/path/to/code,那么它根本不会生成html。$ py.test --cov-report html test_smoke.py
== test session starts ==
platform linux2 -- Python 2.7.12, pytest-3.4.0, py-1.5.2, pluggy-0.6.0 rootdir: /home/someuser/somedir, inifile: plugins: xdist-1.22.0, forked-0.2, cov-2.5.1 collected 3 items
test_smoke.py ... [100%]
== 3 passed in 0.67 seconds ==
我们可以看到没有消息表明输出是创建的。。。但是如果我们指定--cov=。。。$ py.test --cov-report html test_smoke.py --cov=/path/to/code
== test session starts ==
platform linux2 -- Python 2.7.12, pytest-3.4.0, py-1.5.2, pluggy-0.6.0
rootdir: /home/someuser/somedir, inifile:
plugins: xdist-1.22.0, forked-0.2, cov-2.5.1
collected 3 items
test_smoke.py ... [100%]
---------- coverage: platform linux2, python 2.7.12-final-0 ----------
Coverage HTML written to dir htmlcov
我们现在看到没有通过测试的统计信息,而是看到覆盖率被写入HTML并发送到默认目录:./htmlcov
注意:如果需要其他目录,请将/path/to/directory附加到输出样式html->;py.test--cov report html:/path/to/htmldir test_smoke.py--cov=/path/to/code
如果您看到一个普通的html文件,这表明您的问题可能是--cov=/path/to/my/pkg。。。你确定你正在测试的代码就在这里吗?