Py.Test : Reporting and HTML output

℡╲_俬逩灬. 提交于 2019-12-06 18:27:29

问题


This is not a technical question at all really. However, I can not locate my .HTML report that is supposed to be generated using:

py.test --cov-report html pytest/01_smoke.py

I thought for sure it would place it in the parent location, or the test script location. Does neither and I have not been able to locate. So I am thinking it is not being generated at all?


回答1:


I think you also need to specify the directory/file you want coverage for like py.test --cov=MYPKG --cov-report=html after which a html/index.html is generated.




回答2:


if you do not specify --cov=/path/to/code then it will not generate the html at all.

$ 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 ==

We can see that there is no message that output was created... However if we specify --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

We now see that there are no stats for tests that passed, instead we see that coverage was written to HTML and sent to the default directory: ./htmlcov

NOTE: if you want a different directory, then affix :/path/to/directory to the output style html -> py.test --cov-report html:/path/to/htmldir test_smoke.py --cov=/path/to/code

If you see a plain html file, this is an indication that your problem is the --cov=/path/to/my/pkg perhaps... are you sure that the code you are testing lives here?



来源:https://stackoverflow.com/questions/17557813/py-test-reporting-and-html-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!