原文链接,感谢作者:http://www.manongjc.com/detail/18-uxknglitylthfjx.html
1、测试案例:
#test_allure_demo.py
import pytest
import allure
@pytest.fixture(scope="session")
def login():
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 TestC:
@allure.testcase("http://www.tc.com")
@allure.issue("https://www.bug.com/")
@allure.title("测试用例的标题")
@allure.story("用户故事:1")
@allure.severity("blocker")
def test_1(self,login):
'''我是用例1的描述内容,看的见我不'''
step_1()
step_2()
@allure.story("用户故事:2")
def test_2(self,login):
print("测试用例2")
step_1()
step_3()
@allure.epic("epic对大story的一个描述性标签")
@allure.feature("模块块2")
class TestC2():
@allure.story("用户故事:33")
def test_3(self,login):
print("测试用例test_3")
step_1()
@allure.story("用户故事:44")
def test_4(self,login):
print("测试用例test_4")
step_3()
2、执行并打开报告:
执行用例: pytest -vs test_allure_demo.py --alluredir ./report/a ,
打开报告:allure serve ./report/a
3、allure 报告页面
4、按需执行用例:
a.选择运行你要执行epic的用例:
pytest --alluredir ./report/allure --allure-epics=epic对大Story的一个描述性标签
b.选择运行你要执行features的用例:
pytest --alluredir ./report/allure --allure-features=模块块2
c.选择运行你要执行features的用例:
pytest --alluredir ./report/allure --allure-stories=“用户故事:1”