2013-07-09 60 views
4

這真的不是一個技術問題。但是,我無法找到是應該使用生成我的.HTML報告:Py.Test:報告和HTML輸出

py.test --cov報告HTML pytest/01_smoke.py

我想肯定它會將其放在父級位置或測試腳本位置。既沒有,我也沒有找到。所以我認爲它並沒有被生成?

+0

您是否嘗試過'py.test --help'? –

+0

是的,我有。我會在這裏發佈,以顯示它沒有比我已經有更多的信息。 '--cov-report =要生成的報告的類型類型:術語,術語缺失, 註釋,html,xml(多允許)' – Dave

回答

8

我想你還需要指定你想覆蓋的目錄/文件,例如py.test --cov=MYPKG --cov-report=html,之後生成一個html/index.html

+0

謝謝,hpk42。這確實奏效。輸出.html基本上是腳本的打印輸出,但是。這是一個進步。 – Dave

+0

看起來像你需要單獨easy_install pytest-cov項目。 – jayunit100

1

如果你沒有指定--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 /目錄到輸出樣式html - > py.test --cov-report html:/ path/to/htmldir test_smoke.py --cov =/path/to/code

如果您看到一個純html文件,這表示您的問題是--cov =/path/to/my/pkg也許...... 您確定您正在測試的代碼在此處生存嗎?