1. 程式人生 > 其它 >pytest+allure生成美化報告

pytest+allure生成美化報告

pytest可以生成junit格式的xml報告和HTML報告,命令如下:

pytest test_demo.py --junitxml=report.xml
pytest test_demo.py --html=report.html #需要安裝外掛:pip install pytest-html

然後在同目錄下生成了report.html檔案,開啟如下:

介面看著不太美觀,不過有第三方的Allure 報告更加靈活美觀,下面我們來介紹allure使用

  1. allure包下載:https://github.com/allure-framework/allure2/releases

  2. 解壓 -> 進入bin目錄 -> 執行allure.bat,

  3. 把bin目錄加入PATH環境變數

  4. 安裝 allure-pytest外掛

pip install allure-pytest
  1. 生成報告
pytest [測試檔案] -s -q --alluredir=./result #--alluredir用於指定儲存測試結果的路徑)
  1. 檢視報告
    方式一:直接開啟預設瀏覽器展示報告
allure serve ./result/

方式二:從結果生成報告

allure generate ./result/ -o ./report/ --clean   (覆蓋路徑加--clean) #生成報告
allure open -h 127.0.0.1 -p 8883 ./report/		#開啟報告

效果是一樣的就不展示圖片了