python 主流自動化測試報告插件有三個:HTMLTestRunner、BeautifulReport 和 Allure
下面簡單介紹allure的安裝使用
前提條件:測試框架為pytest(已經安裝pytest pip install pytest)
1、安裝pytest的allure插件 pip install pytest
2、allure是依賴java環境
去allure官網下載,解壓后將bin路徑設置到環境變量path中
3、在main中運行測試代碼 pytest.main(['--alluredir', './Outputs/reports']) ['操作命令','報告保存地址']
4、如果運行時出現以下錯誤:
module 'allure' has no attribute 'severity_level'
這很可能因為你之前安裝了allure-pytest的低版本,需要卸載掉,然后安裝比較新的版本;
命令執行如下:
pip uninstall pytest-allure-adaptor
pip install allure-pytest
5、生成的報告時json格式數據,無法直觀的查看測試結果,執行以下命令將數據轉化為圖形界面
allure generate ./<測試生成的數據>/ -o ./<測試報告存放的路徑>/ --clean
例:allure generate ./Outputs/reports/ -o ./report/ --clean
這樣在report目錄下就生成了Allure的測試報告了。–clean目的是先清空測試報告目錄,再生成新的測試報告。
6、打開index.html文件查看測試結果