1. 程式人生 > >pytest 6 生成html報告

pytest 6 生成html報告

src ipp 所有 查詢 直接 存放位置 all 顯示效果 兼容

前言:pytest-HTML是一個插件,pytest用於生成測試結果的HTML報告。兼容Python 2.7,3.6

1.github上源碼地址【https://github.com/pytest-dev/pytest-html】

2.pip安裝

  pip install pytest-html

技術分享圖片

3.執行方法

  pytest --html=report.html

html報告

1.打開cmd,cd到需要執行pytest用例的目錄,執行指令:pytest --html=report.html

技術分享圖片

2.執行完之後,在當前目錄會生成一個report.html的報告文件,顯示效果如下:

技術分享圖片

指定報告路徑

1.直接執行”pytest --html=report.html”生成的報告會在當前腳本的同一路徑,如果想指定報告的存放位置,放到當前腳本的同一目錄下的report文件夾裏

pytest --html=./report/report.html

技術分享圖片

2.如果想指定執行某個.py文件用例或者某個文件夾裏面的所有用例,需加個參數。具體規則參考【pytest文檔1-用例運行規則】

技術分享圖片

顯示選項

默認情況下,“ 結果”表中的所有行都將被展開,但具測試通過的行除外Passed。

可以使用查詢參數自定義此行為:?collapsed=Passed,XFailed,Skipped。

pytest 6 生成html報告