1. 程式人生 > 其它 >Pytest使用pytest-html和allure生成測試報告

Pytest使用pytest-html和allure生成測試報告

Pytest-html

1、安裝命令pip3 install pytest-html,如下圖:

  執⾏後,會在當前⽬錄下⽣成 ⼀個report.html的⽂件,開啟後會展示詳細的測試報告,執行該命令python -m pytest tests/ --html=report/index.html

將會在report資料夾下生成index.html報告。

2、pytest-rerunfailures

  對執行失敗的再次執行。安裝命令pip3 install pytest-rerunfailures,安裝如下圖:

3、pip3 install -U pytest升級版本

  為了是測試報告看起來更加的舒適,我們需要安裝allure-2.7.0,將解壓好的allure-2.7.0資料夾(解壓后里面有兩個資料夾)下的bin開啟,複製路徑,

在此電腦的屬性中選擇高階系統設定配置環境變數,再選擇Administrator的使用者變數下選擇Path,將檔案路徑貼上。

  在cmd中執行allure檢測安裝是否成功,如圖安裝成功

再執行以下命令:

python -m pytest tests --alluredir=report/result(result下生成json的檔案)

allure generate report/result/ -o report/html --clean (report下生成html的目錄,裡面包含了html的測試報告)

allure serve report/result(啟動allure的服務,自動開啟測試報告)

將會生成一個完美的測試報告,如下圖: