前提:已安裝 allure/allure-pytest/pytest-html
首先驗證allure版本
通過hrun -h可查
主要兩個步驟 1.用 --alluredir運行測試用例 2.生成報告
進入測試用例目錄下
1、指定運行用例:pytest 測試文件 --alluredir report 或者 hrun 測試文件 --alluredir report
測試文件:如果是填寫文件名,默認是當前路徑的文件,如果要運行指定文件,則測試文件要帶上路徑
reprort: 是用於存放的文件(默認是存放在當前路徑,如果要存放在指定路徑,則文件名要帶上路徑)
pytest運行的測試用例只能是.py格式,hrun運行的測試用例,可以是pytest格式,也可以是yml格式
步驟一:運行測試用例
pytest hetest_re_test.py --alluredir report
或者
hrun hetest_re.yml --alluredir=report
運行結果如下:
會在當前文件夾下生成測試結果文件夾 .pytest_cache、report
步驟二 :生成報告
allure generate report # 默認在當前目錄下生成allure-report文件
allure generate report -o allure-report --clean # --clean是為了清空已有的測試報告; -o allure-report 是指定清空測試報告的文件allure-report
allure generate report運行結果如下:
allure generate report -o allure-report --clean運行結果如下:
會在當前文件夾生成 allure-report 文件夾,包含HTML測試報告 index.html ,然后用瀏覽器打開查看
2、全部運行:pytest --alluredir report
全部運行的是test_.*py的文件
pytest --alluredir report
會在當前文件夾下生成測試結果文件夾 .pytest_cache、report
allure generate report
同樣會在當前文件夾生成 allure-report 文件夾,包含HTML測試報告 index.html,含所有測試用例結果數據