介面自動化測試:pytest+allure基本使用
阿新 • • 發佈:2020-10-10
一、環境準備:
1、安裝allure
2、安裝allure-pytest:pip installallure-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 使用者管理模組,商品管理模組