第一步:pip install pytest-allure-adaptor
第二步:編寫用例
import allure import pytest """ Feature: 標注主要功能模塊 Story: 標注Features功能模塊下的分支功能 Severity: 標注測試用例的重要級別 Step: 標注測試用例的重要步驟 Issue和TestCase: 標注Issue、Case,可加入URL attach: 標注增加附件 Environment: 標注環境Environment字段 """ # 環境 allure.MASTER_HELPER.environment(域名="127.0.0.1") @allure.MASTER_HELPER.feature("測試") class TestClassOne: @allure.MASTER_HELPER.story("test_one_1") @allure.MASTER_HELPER.severity("normal") # 運行步驟 @allure.MASTER_HELPER.step("單元相當") def test_one_1(self): with allure.MASTER_HELPER.step("獲取變量a"): a = 3 with allure.MASTER_HELPER.step("獲取變量b"): b = 2 allure.MASTER_HELPER.attach("預期結果", "{0}".format("1")) allure.MASTER_HELPER.attach("實際結果", "{0}".format("2")) x = "this" assert 't' in x @allure.MASTER_HELPER.story("test_two_2") @allure.MASTER_HELPER.severity("normal") def test_two_2(self): """用例描述拉""" x = "hello" assert hasattr(x, 'check') @allure.MASTER_HELPER.story("test_one_1") @allure.MASTER_HELPER.severity("normal") def test_one_3(self): x = "this" assert 't' in x @allure.MASTER_HELPER.story("test_two_2") @allure.MASTER_HELPER.severity("normal") def test_two_4(self): x = "hello" assert hasattr(x, 'check') @allure.MASTER_HELPER.story("test_one_1") @allure.MASTER_HELPER.severity("normal") def test_one_5(self): x = "this" assert 't' in x @allure.MASTER_HELPER.story("test_two_2") @allure.MASTER_HELPER.severity("normal") def test_two_6(self): x = "hello" assert hasattr(x, 'check') @allure.MASTER_HELPER.story("test_one_1") @allure.MASTER_HELPER.severity("trivial") def test_one_7(self): x = "this" assert 't' in x @allure.MASTER_HELPER.story("test_two_2") @allure.MASTER_HELPER.severity("normal") def test_two_8(self): x = "hello" assert hasattr(x, 'check') import os if __name__ == '__main__': """ --reruns 重試 -s 顯示print內容 """ pytest.main(['-s', '--reruns', '10', '-q', 'test_pytestdemo.py', '--alluredir', './report/xml']) os.system("allure generate report/xml -o report/html")
#執行后自動打開報告 allure serve allure
執行一下命令
生成xml數據
pytest -s -q --alluredir=report
生成報告
allure generate report/ -o report/html