本篇文章寫的是通過allure生成測試報告,當然pytest有自己生成測試報告方式,官網網站也提供了報告優化的代碼。但是相比起來還是allure的報告更能直觀的顯示;
1.allure環境搭建
安裝python支持的allure第三方模塊
pip install allure-pytest
安裝allure命令行工具,后期用來啟動服務
# github 中下載 https://github.com/allure-framework/allure2/releases
將下載的allure中的bin目錄配置到環境變量
2.編寫用例,通過allure裝飾器形式標記用例(詳細的標記在下方)
import allure @allure.feature('計算器模塊') class Test_login(): @allure.story('第一個測試用例') def test_1(self): assert 1+2 == 3 @allure.story('第二個測試用例') def test_2(self): assert 2-2 == 0 @allure.story('第三個測試用例') def test_3(self): assert 3*3 == 9 @allure.story('第四個測試用例') def test_4(self): assert 10/2 ==5
3.執行用例
# 指定報告存放路徑 pytest test_5.py --alluredir ./report
測試結束后報告並非html格式
啟動allure服務,展示測試報告
allure serve report # report為上一步指定的報告路徑,系統會自動分配端口
4.allure詳細標記用例格式
臨時掛上官網描述,后期補充 https://docs.qameta.io/allure/#_pytest