Pytest學習(十八)- pytest報告美化之allure2的使用
阿新 • • 發佈:2020-11-29
一:環境配置
安裝外掛
allure 是一個輕量級的,靈活的,支援多語言,多平臺的report框架。
Allure2官網地址:https://github.com/allure-framework/allure2
pip3 install allure-pytest -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
安裝Allure2
這裡我以win10環境為例,需要在Power Shell視窗中執行scoop install allure命令:
1、Win鍵+X 調出Power Shell視窗
2、Power Shell視窗執行如下命令(先安裝scoop):
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
執行後,使用scoop命令檢視是否正確安裝(下圖說明安裝正確):
3、Power Shell視窗執行scoop install allure命令(如下圖安裝成功):
** 注意:win7下要執行pip install pytest-adaptor-allure安裝allure的介面卡!**
二、如何使用
命令列執行
用法:新增 --alluredir 選項,並提供指向應儲存結果的資料夾的路徑
示例如下:
pytest -n auto --alluredir=allure
生成出來的結果
可以看到,這不是我們想要的結果,一堆json、txt檔案....
生成視覺化報告
要在測試完成後檢視實際報告,需要定位到結果檔案同級目錄,使用Allure命令列來讓測試結果生成報告,示例程式碼如下:
allure serve allure
命令列截圖:
接著我們再來看下優化後的報告,結果如下:
三、Allure報告結構
- Overview:總覽
- Categories:類別,預設是分了failed和error,凡是執行結果是其中一個的都會被歸到類裡面,可以通過這裡快捷檢視哪些用例是failed和error的
- Suites:測試套件,就是所有用例的層級關係,可以根據package、module、類、方法來查詢用例
- Graphs:測試結果圖形化,包括用例執行結果的分佈圖,優先順序,耗時等
- Timeline:可以看到測試用例精確的測試時序(執行順序),包括執行時間
- Behaviors:行為驅動,根據epic、feature、story來分組測試用例(後面會講到)
- Packages:這就是按照package、module來分組測試用例了