前言
pytest+allure是最完美的結合了,關於allure的使用,本篇做一個總結。
allure報告可以很多詳細的信息描述測試用例,包括epic、feature、story、title、issue、testcase、severity等
環境准備
- python 3.6
- pytest 4.5.0
- allure-pytest 2.8.6
allure用例描述
使用方法 | 參數值 | 參數說明 |
---|---|---|
@allure.epic() | epic描述 | 敏捷里面的概念,定義史詩,往下是feature |
@allure.feature() | 模塊名稱 | 功能點的描述,往下是story |
@allure.story() | 用戶故事 | 用戶故事,往下是title |
@allure.title(用例的標題) | 用例的標題 | 重命名html報告名稱 |
@allure.testcase() | 測試用例的鏈接地址 | 對應功能測試用例系統里面的case |
@allure.issue() | 缺陷 | 對應缺陷管理系統里面的鏈接 |
@allure.description() | 用例描述 | 測試用例的描述 |
@allure.step() | 操作步驟 | 測試用例的步驟 |
@allure.severity() | 用例等級 | blocker,critical,normal,minor,trivial |
@allure.link() | 鏈接 | 定義一個鏈接,在測試報告展現 |
@allure.attachment() | 附件 | 報告添加附件 |
測試案例
pytest結合allure測試用例
import pytest
import allure
@pytest.fixture(scope="session")
def login_fixture():
print("前置條件:登錄")
@allure.step("步驟1")
def step_1():
print("操作步驟---------------1")
@allure.step("步驟2")
def step_2():
print("操作步驟---------------2")
@allure.step("步驟3")
def step_3():
print("操作步驟---------------3")
@allure.epic("epic對大Story的一個描述性標簽")
@allure.feature("測試模塊")
class TestDemoAllure():
@allure.testcase("http://49.235.x.x:8080/zentao/testcase-view-6-1.html")
@allure.issue("http://49.235.x.x:8080/zentao/bug-view-1.html")
@allure.title("用例的標題")
@allure.story("用戶故事:1")
@allure.severity("critical")
def test_case_1(self, login_fixture):
'''case description: 1.點文章分類導航標簽 -跳轉編輯頁面 2.編輯頁面輸入,分類名稱,如:上海-悠悠-可以輸入 3.點保存按鈕保存成功 '''
step_1()
step_2()
@allure.story("用戶故事:2")
def test_case_2(self, login_fixture):
print("測試用例1")
step_1()
step_3()
@allure.epic("epic對大Story的一個描述性標簽")
@allure.feature("模塊2")
class TestDemo2():
@allure.story("用戶故事:3")
def test_case_3(self, login_fixture):
print("測試用例1")
step_1()
@allure.story("用戶故事:4")
def test_case_4(self, login_fixture):
print("測試用例1")
step_3()
報告展示
cd到用例目錄執行用例生成allure報告
pytest --alluredir ./report/allure
allure serve ./report/allure
報告展示內容
命令行參數
pytest運行用例的時候可以加上allure標記用例的參數
--allure-severities=SEVERITIES_SET
Comma-separated list of severity names. Tests only
with these severities will be run. Possible values
are: blocker, critical, normal, minor, trivial.
--allure-epics=EPICS_SET
Comma-separated list of epic names. Run tests that
have at least one of the specified feature labels.
--allure-features=FEATURES_SET
Comma-separated list of feature names. Run tests that
have at least one of the specified feature labels.
--allure-stories=STORIES_SET
Comma-separated list of story names. Run tests that
have at least one of the specified story labels.
--allure-link-pattern=LINK_TYPE:LINK_PATTERN
Url pattern for link type. Allows short links in test,
like 'issue-1'. Text will be formatted to full url
with python str.format().
選擇運行你要執行epic的用例
pytest --alluredir ./report/allure --allure-epics=epic對大Story的一個描述性標簽
選擇運行你要執行features的用例
pytest --alluredir ./report/allure --allure-features=模塊2
選擇運行你要執行features的用例
pytest --alluredir ./report/allure --allure-stories="用戶故事:1"