Pytest系列(23)- allure打标记,@allure.feature()、@allure.story()、@allure.severity()的详细使用
如果你还想从头学起Pytest,可以看看这个系列的文章哦!
https://www.cnblogs.com/poloyy/category/1690628.html
前言
- 前面几篇文章主要介绍了allure的特性,这篇文章我们就来讲下allure的标记用法
 - 有时候我们写pytest的时候,会用到 @pytest.mark 但并不会显示在allure报告上
 - 而allure也提供了三种类型的标记装饰器,它们是可以显示在allure报告上的
 
allure的标记装饰器
- BDD样式的标记装饰器
 - 优先级(严重程度)标记装饰器
 - 自定义标记装饰器
 
BDD标记装饰器
提供了两个装饰器
@allure.feature
@allure.story
直接上代码栗子
#!/usr/bin/env python
# -*- coding: utf-8 -*- """
__title__ =
__Time__ = 2020-04-19 14:27
__Author__ = 小菠萝测试笔记
__Blog__ = https://www.cnblogs.com/poloyy/
""" import allure def test_without_any_annotations_that_wont_be_executed():
pass @allure.story('epic_1')
def test_with_epic_1():
pass @allure.story('story_1')
def test_with_story_1():
pass @allure.story('story_2')
def test_with_story_2():
pass @allure.feature('feature_2')
@allure.story('story_2')
def test_with_story_2_and_feature_2():
pass
我们先看看没有设置标记装饰器时,allure报告是咋样的


加了@allure.feature和@allure.story之后,allure报告又是怎么样的呢


知识点
story是feature的子集,当测试用例有 @allure.feature、@allure.story 时,在报告上会先显示feature,点开之后再显示story【可以想象成,安徒生童话(feature)有很多个童话故事(story)】
如果不加 @allure.feature、@allure.story 时,在Behaviors栏目下,测试用例都不会分类显示,当用例多的时候可能看的花里胡哨
总结
倘若是用pytest+allure写项目的话,又想用@pytest.mark.xxx 来自定义标记的话可以尝试用 @allure.feature、@allure.story 替换,毕竟可以显示在报告上
问题来了,用命令行方式运行时,可以指定运行某个story或者feature吗?
答案是:当然可以!!跟@pytest.mark.xxx没啥区别哦!!
- --allure-features
 - --allure-stories
 
譬如
pytest tests.py --allure-stories story_1,story_2
pytest tests.py --allure-features feature2 --allure-stories story2
@ allure.severity
作用:按严重性(优先级)来标记测试用例,它使用allure.severity_level枚举值作为参数
先看看枚举类有哪些常量
严重程度最高blocker,最低trivial
class Severity(str, Enum):
BLOCKER = 'blocker'
CRITICAL = 'critical'
NORMAL = 'normal'
MINOR = 'minor'
TRIVIAL = 'trivial'
看看代码栗子
#!/usr/bin/env python
# -*- coding: utf-8 -*- """
__title__ =
__Time__ = 2020-04-19 14:50
__Author__ = 小菠萝测试笔记
__Blog__ = https://www.cnblogs.com/poloyy/
""" import allure def test_with_no_severity_label():
pass @allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_severity():
pass @allure.severity(allure.severity_level.NORMAL)
def test_with_normal_severity():
pass @allure.severity(allure.severity_level.NORMAL)
class TestClassWithNormalSeverity(object): def test_inside_the_normal_severity_test_class(self):
pass @allure.severity(allure.severity_level.CRITICAL)
def test_inside_the_normal_severity_test_class_with_overriding_critical_severity(self):
pass
运行结果,查看allure报告
其实就是测试用例多了个优先级severity属性而已...

命令行方式
也可以通过命令行参数运行指定severity的测试用例哦
pytest tests.py --allure-severities normal,critical
Pytest系列(23)- allure打标记,@allure.feature()、@allure.story()、@allure.severity()的详细使用的更多相关文章
- Pytest 系列(25)- 标记用例级别 @allure.
		
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 平时写测试用例也会划分优先级 ...
 - Pytest系列(13)- 重复执行用例插件之pytest-repeat的详细使用
		
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 平常在做功能测试的时候,经常 ...
 - Pytest系列(20)- allure结合pytest,allure.step()、allure.attach的详细使用
		
如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 allure除了支持pyte ...
 - 【pytest系列】- mark标记功能详细介绍
		
如果想从头学起pytest,可以去看看这个系列的文章! https://www.cnblogs.com/miki-peng/category/1960108.html mark标记  在实际工作中, ...
 - pytest系列(二):筛选用例新姿势,mark 一下,你就知道。
		
pytest系列(一)中给大家介绍了pytest的特性,以及它的编写用例的简单至极. 那么在实际工作当中呢,我们要写的自动化用例会比较多,不会都放在一个py文件里. 如下图所示,我们编写的用例存放在不 ...
 - 蓝 / 绿部署(Blue/Green)  金丝雀发布(Canary Release)  功能标记(Feature Flagging)
		
https://www.cnblogs.com/apanly/p/8784096.html 最终,我选择了 GraphQL 作为企业 API 网关 蓝 / 绿部署(Blue/Green) 金丝雀发布( ...
 - Pytest系列(一)初次了解
		
在之前,我分享过unittest系列,后来有很多人问我,能不能出pytest的教程,正好最近在整理pytest相关的资料,那么,就趁着这个机会,去和大家分享一下pytest系列. pytest是一个非 ...
 - C#开发BIMFACE系列23 服务端API之获取模型数据8:获取模型链接信息
		
系列目录 [已更新最新开发文章,点击查看详细] 在Revit等BIM设计工具中可以给模型的某个部位添加链接信息.即类似于在Office Word.Excel 中给一段文字添加本地文件链接或者网 ...
 - .NET平台系列23:.NET Core/.NET5/.NET6 和 .NET Framework 的选择建议
		
系列目录 [已更新最新开发文章,点击查看详细] 有两种支持的 .NET 实现可用于生成服务器端应用: .NET Framework .NET Core/5+,包括 .NET Core..NET ...
 
随机推荐
- ElegantSnap 一个优雅的,易用的iOS/tvOS/macOS自动布局框架, 超级详细的使用教程,多视图水平等宽/垂直等高排列
			
ElegantSnap ElegantSnap(Base on SnapKit) to make Auto Layout easy and elegant on both iOS and OS X. ...
 - Mol Cell Proteomics. | Prediction of LC-MS/MS properties of peptides from sequence by deep learning (通过深度学习技术根据肽段序列预测其LC-MS/MS谱特征) (解读人:梅占龙)
			
通过深度学习技术根据肽段序列预测其LC-MS/MS谱特征 解读人:梅占龙 质谱平台 文献名:Prediction of LC-MS/MS properties of peptides from se ...
 - (一)iview的校验TypeError: Cannot read property 'validateField' of undefined"
			
一.问题描述 我是在自己封装了一个地址级联选择,然后想要每次改变了其中数据的时候,就进行一次单独校验,所以用到了iview对部分表单字段进行校验的方法validateField.其实一开始使用的时候是 ...
 - [树的深度] Party
			
Party A company has n employees numbered from 1 to n. Each employee either has no immediate manager ...
 - Arcgis中制作热力图
			
摘要 使用核函数根据点或折线 (polyline) 要素计算每单位面积的量值以将各个点或折线 (polyline) 拟合为光滑锥状表面. 插图
 - 已知IP地址和子网掩码求出网络地址、广播地址、地址范围和主机数(转载https://blog.csdn.net/qq_39026548/article/details/78959089)
			
假设IP地址为128.11.67.31,子网掩码是255.255.240.0.请算出网络地址.广播地址.地址范围.主机数.方法:将IP地址和子网掩码转化成二进制形式,然后进行后续操作. IP地址和子网 ...
 - 怎么在三层架构中使用Quartz.Net开源项目(与数据库交互)
			
1.首先在项目中先创建一个控制台应用程序 2.然后右击项目中的[引用],可以[添加引用],也可以[管理NuGet程序包],作者使用的是[添加引用],添加本地应用.版本不同,所使用的方式不同.需要此版本 ...
 - Activiti任务分配
			
分配任务负责人 一.固定分配 在进行业务流程建模时指定固定的任务负责人 在properties 视图中,填写Assignee 项为任务负责人. 注意: 由于固定分配方式,任务只管一步一步执行任务,执行 ...
 - 大流量大负载的Kafka集群优化实战
			
前言背景 算法优化改版有大需求要上线,在线特征dump数据逐步放量,最终达到现有Kafka集群5倍的流量,预计峰值达到万兆网卡80%左右(集群有几十个节点,网卡峰值流出流量800MB左右/sec.写入 ...
 - Modbus协议和应用开发介绍
			
因业务需要了解Modbus协议的使用,因此对Modbus的协议,以及相应的C#处理应用进行了解,针对协议的几种方式(RTU.ASCII.TCPIP)进行了封装,以及对Modbus的各种功能码的特点进行 ...