一、環境准備:
1、安裝allure
2、安裝allure-pytest:pip install allure-pytest
二、allure基本參數說明
三、實踐代碼
#conftest.py
import pytest @pytest.fixture(scope="session") def login_fixture(): """需要先登錄"""
print("前置條件") yield
print("后置條件")
#steps.py
import allure @allure.step("步驟1") def step1(): pass @allure.step("步驟2") def step2(): pass @allure.step("步驟3") def step3(): pass
#test_demo.py
import pytest import allure from test_allure.step import step1, step2, step3 @allure.feature("用戶管理模塊") class TestDemo(): @allure.story("測試用例標題") @allure.issue("http://bug.html") @allure.testcase("http://testcase.html") def test_update(self): """測試更新接口"""
print("測試更新接口") step1() step2() step3 @allure.story("測試用例標題1") @allure.issue("http://bug1.html") @allure.testcase("http://testcase1.html") def test_del(self): """測試刪除接口"""
print("測試刪除接口") step1() step2() step3 @allure.feature("商品管理模塊") class TestDemo1(): @allure.story("測試用例標題") @allure.issue("http://bug.html") @allure.testcase("http://testcase.html") @allure.severity("blocker") def test_update(self): """測試更新接口"""
print("測試更新接口") step1() step2() step3 @allure.story("測試用例標題1") @allure.issue("http://bug1.html") @allure.testcase("http://testcase1.html") @allure.severity("critical") def test_del(self): """測試刪除接口"""
print("測試刪除接口") step1() step2() step3
命令行執行pytest命令生成allure的測試報告
pytest --alluredir ./allure/report8
可以看到生成的是json、txt格式的數據
在命令行執行allure命令,啟動一個web服務,將上一步生成的數據生成HTML進行可視化
allure serve ./allure/report8
最后,可以按照allure標記過濾執行部分測試用例:
比如:
pytest --alluredir ./allure/report7 --allure-features 用戶管理模塊,商品管理模塊