前言
前面我们提到使用allure 可以生成漂亮的测试报告,下面就Allure 标记我们做详细介绍。
allure 标记
包含:epic,feature, story, title, testcase, issue, description, step, serverity, link, attachment

常用的标记
@allure.feature # 用于描述被测试产品需求,可以理解为模块,一般在测试类上面加
@allure.story # 用于描述feature的用户场景,可以理解为测试场景,一般在测试用例上加
with allure.step # 用于描述测试步骤
allure.attach # 用于向测试报告中输入一些附加的信息,通常是一些测试数据,截图等
关系:feature是story父级,feature 是story父级,是包含关系,从大至小 (1)feature:模块名称 (2)story:用例故事或场景 (3)step :用例的测试步骤
使用:它们可以同时使用,也可以单独使用,也可以不使用
项目运用:
1、我们要测试两个流程:账单生成;账单支付;
2、账单生成有几个模块:订单模块-合同模块-订单交付模块
3、以订单模块为例子:
生成订单是一个测试用例
步骤包括:
1、前置条件: 获取用户信息,获取供应商信息
2、测试步骤:获取需求列表-获取需求详情-获取品牌信息-保存需求-获取最新需求
前置条件:
前置条件有2个信息获取:用户信息和供应商信息,所以我们提前执行获取并保存到全局变量中,方便后面用例使用。这里用的是用例,也可以用feature @pytest.fixture(scope="class")

测试用例:
生成订单,包括4个步骤:获取已完成的需求-需求详情-品牌详情-保存需求-获取需求中的订单Code

测试报告
报告首页:

账单生成流程的详情:
订单模块的用例都列出来了

生成订单用例:

问题:
刚刚我们注意到,登陆流程是被跳过了,怎么实现呢?
方式一:@pytest.mark.skip 跳过

方式二:使用mark标签实现
1、注册标签
markers ``=
``login
pt

2、使用标签


3、指定运行标签,排除login

方式三:指定运行某个feature、story

添加下面的命令行参数就行
只运行 epic 名为 test 的测试用例
pytest --alluredir ./report/allure --allure-epics=test
只运行 feature 名为 模块 的测试用例
pytest --alluredir ./report/allure --allure-features=模块
只运行 story1、story2 的测试用例(也可以不用=号 空格就行了哦)
pytest tests.py --allure-stories story1,story2
指定 feature+story
pytest tests.py --allure-features feature2 --allure-stories story2
