pytest结合 allure 打标记之的详细使用

前言

前面我们提到使用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

最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走!

软件测试面试文档

我们学习必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有字节大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。

相关推荐
把头塞进显示器1 天前
电商平台-测试报告
python·selenium·pytest
昔我往昔6 天前
pytest日志问题排查记录
python·pytest
黄昏恋慕黎明9 天前
博客论坛技术迭代
python·pytest
2601_962078239 天前
Python接口自动化流程(pytest)
python·pytest·接口自动化·测试框架·断言
杨女士YRJ9 天前
python+pytest+01
python·pytest
2601_9620782310 天前
Python接口自动化框架:pytest
python·pytest·接口自动化·测试框架·restfulapi
2601_9620781910 天前
Appium+Python+pytest自动化测试框架详解
自动化测试·python·appium·pytest·移动应用
2601_9622845012 天前
安卓APP UI自动化测试:Python + UiAutomator2 + pytest + pytest-html
python·pytest·uiautomator2·ui自动化测试·安卓app
2601_9623008112 天前
基于pytest的接口自动化测试:使用requests模块的实战项目与接口关联方法详解
接口自动化测试·测试用例·pytest·接口关联·requests模块
2601_9623008112 天前
Python + Requests + Pytest + Excel + Allure:接口自动化测试项目实战
python·excel·pytest·allure·requests