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 ...
随机推荐
- Shell:sed用法 - 查找并替换字符串
原文链接 语法 sed 's/serach_str/replace_str/g' file_path 在某个文件中查找所有的serach_str并替换为replace_str 参数 描述 serach ...
- Journal of Proteome Research | iHPDM: In Silico Human Proteome Digestion Map with Proteolytic Peptide Analysis and Graphical Visualizations(iHPDM: 人类蛋白质组理论酶解图谱的水解肽段分析和可视化展示)| (解读人:邓亚美)
文献名:iHPDM: In Silico Human Proteome Digestion Map with Proteolytic Peptide Analysis and Graphical Vi ...
- c# winform 访问WebServices 服务(通过WEB引用的方式进行访问)
第一步.Winform项目引用WEB服务 第二步.代码声明实例化 Web引用 YzServ.TestServ yzserv = new WebYzServ.TestServ(); yzserv.AAA ...
- 目标检测 | 经典算法 Cascade R-CNN: Delving into High Quality Object Detection
作者从detector的overfitting at training/quality mismatch at inference问题入手,提出了基于multi-stage的Cascade R-CNN ...
- python制作一键启动脚本
我们的系统环境或许没有Python环境,又想使用脚本,这就要使该脚本能脱离Python环境独立运行,比如说将该脚本打包成exe可执行文件等.那么怎么做呢?你可能想到py2exe和pyinstaller ...
- Mysql失败,异常pymysql.err.InternalError: (1366, "Incorrect string value: '\\xF0\\x9D\\x90\\xBF;......
问题描述: 插入Mysql时失败了,python代码报如下异常: pymysql.err.InternalError: (1366, "Incorrect string value: '\\ ...
- 为什么你的程序配了classpath还是找不到类
classpath简介 classpath是java程序时拥有的一个系统变量,这个变量可以通过如下方式获取 System.out.println(System.getProperty("ja ...
- 使用Keras构建深度图像搜索引擎
动机 想象一下,如果有数十万到数百万张图像的数据集,却没有描述每张图像内容的元数据.我们如何建立一个系统,能够找到这些图像的子集来更好地回答用户的搜索查询? 我们基本上需要的是一个搜索引擎,它能够根据 ...
- coding++ :HttpClientUtils 封装
1.关键 JAR <!-- <<===================>> httpClient <<===================>> ...
- Unity 游戏框架搭建 2019 (十八~二十) 概率函数 & GameObject 显示、隐藏简化 & 第二章 小结与快速复习
在笔者刚做项目的时候,遇到了一个需求.第一个项目是一个跑酷游戏,而跑酷游戏是需要一条一条跑道拼接成的.每个跑道的长度是固定的,而怪物的出现位置也是在跑道上固定好的.那么怪物出现的概率决定一部分关卡的难 ...