httprunner 3.x學習6 - 生成 html 測試報告
阿新 • • 發佈:2021-06-16
前言
HttpRunner 3.x版可以使用所有的 pytest 外掛,包括測試報告外掛,像的 pytest-html 和 allure-pytest 。
pytest-html
httprunner 安裝的時候,會自動安裝 pytest 和 pytest-html 外掛,對應的版本號是
- pytest 5.4.3
- pytest-html 2.1.1
C:\Users\dell>pip show pytest Name: pytest Version: 5.4.3 C:\Users\dell>pip show pytest-html Name: pytest-html Version: 2.1.1
hrun 生成報告
hrun 命令生成報告的時候,帶上 --html
指定報告路徑
>hrun testcases/login_userinfo_test.py --html=./reports/result.html
--html
引數生成的報告,css檔案是單獨分開的,不方便檢視,可以加上--self-contained-html
引數讓css檔案整合到html上
>hrun testcases/login_userinfo_test.py --html=./reports/result.html --self-contained-html
執行結果
檢視html報告
pytest 生成報告
用 hrun 執行生成的報告會出現一大堆的報錯: OSError: [WinError 6] 控制代碼無效。並且無法顯示 request 和 response 內容。 hrun 執行pytest用例還不太完善,儘量用pytest去執行py指令碼
>pytest testcases/login_userinfo_test.py --html=./reports/result.html --self-contained-html
執行後檢視報告
allure 報告
httprunner3 也可以支援 allure 外掛,需 pip 安裝
> pip install allure-pytest