如果你还想从头学起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()的详细使用的更多相关文章

  1. Pytest 系列(25)- 标记用例级别 @allure.

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 平时写测试用例也会划分优先级 ...

  2. Pytest系列(13)- 重复执行用例插件之pytest-repeat的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 平常在做功能测试的时候,经常 ...

  3. Pytest系列(20)- allure结合pytest,allure.step()、allure.attach的详细使用

    如果你还想从头学起Pytest,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1690628.html 前言 allure除了支持pyte ...

  4. 【pytest系列】- mark标记功能详细介绍

    如果想从头学起pytest,可以去看看这个系列的文章! https://www.cnblogs.com/miki-peng/category/1960108.html mark标记 ​ 在实际工作中, ...

  5. pytest系列(二):筛选用例新姿势,mark 一下,你就知道。

    pytest系列(一)中给大家介绍了pytest的特性,以及它的编写用例的简单至极. 那么在实际工作当中呢,我们要写的自动化用例会比较多,不会都放在一个py文件里. 如下图所示,我们编写的用例存放在不 ...

  6. 蓝 / 绿部署(Blue/Green) 金丝雀发布(Canary Release) 功能标记(Feature Flagging)

    https://www.cnblogs.com/apanly/p/8784096.html 最终,我选择了 GraphQL 作为企业 API 网关 蓝 / 绿部署(Blue/Green) 金丝雀发布( ...

  7. Pytest系列(一)初次了解

    在之前,我分享过unittest系列,后来有很多人问我,能不能出pytest的教程,正好最近在整理pytest相关的资料,那么,就趁着这个机会,去和大家分享一下pytest系列. pytest是一个非 ...

  8. C#开发BIMFACE系列23 服务端API之获取模型数据8:获取模型链接信息

    系列目录     [已更新最新开发文章,点击查看详细] 在Revit等BIM设计工具中可以给模型的某个部位添加链接信息.即类似于在Office Word.Excel 中给一段文字添加本地文件链接或者网 ...

  9. .NET平台系列23:.NET Core/.NET5/.NET6 和 .NET Framework 的选择建议

    系列目录     [已更新最新开发文章,点击查看详细] 有两种支持的 .NET 实现可用于生成服务器端应用: .NET Framework .NET Core/5+,包括 .NET Core..NET ...

随机推荐

  1. 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 ...

  2. [转]【maven】解决Missing artifact jdk.tools:jdk.tools:jar:1.6

    解决在pom.xml文件中出现的Missing artifact jdk.tools:jdk.tools:jar:1.6问题 <dependency> <groupId>jdk ...

  3. Python-时间戳、元组时间的格式、自定义时间格式之间的转换

    一.时间戳.元组时间的格式.自定义时间格式之间的转换 1.下面是三者之间的转换关系: 2.代码如下: import time import datetime print(time.time()) #获 ...

  4. 菜鸟教程-python中的包

    转载自:http://www.runoob.com/python/python-modules.html 包是一个分层次的文件目录结构,它定义了一个由模块及子包,和子包下的子包等组成的 Python ...

  5. POJ1270 toposort+DFS+回溯

    题目链接:http://poj.org/problem?id=1270 这道题其实就是求所有满足条件的topo序,我们考虑到给定的字符是确定的,也就是他们的长度都是一样的,所以为了得到所有的情况,我们 ...

  6. Java日期处理易踩的十个坑

    前言 整理了Java日期处理的十个坑,希望对大家有帮助. 一.用Calendar设置时间的坑 反例: Calendar c = Calendar.getInstance(); c.set(Calend ...

  7. KMP 算法简单解释

    ​ 讲KMP算法,离不开BF,实际上,KMP就是BF升级版,主要流程和BF一样 ​ 不同是在匹配失败时能利用子串的特征减少回溯,利用根据子串特征生成的Next数组来减少 <( ̄︶ ̄)↗[GO!] ...

  8. 《数据库优化》- MySQL视图

    一.什么是视图 视图,是基于一个表或多个表或视图的逻辑表,本身不包含数据,通过它可以对表里面的数据进行查询和修改,视图基于的表称为基表.视图是存储在数据字典里的一条select语句. 通俗地讲,视图就 ...

  9. Check If It Is a Straight Line

    2019-10-21 10:35:33 问题描述: 问题求解: public boolean checkStraightLine(int[][] coordinates) { int n = coor ...

  10. 构建安全可靠的微服务 | Nacos 在颜铺 SaaS 平台的应用实践

    作者 | 殷铭  颜铺科技架构师 本文整理自架构师成长系列 3 月 19 日直播课程. 关注"阿里巴巴云原生"公众号,回复 "319",即可获取对应直播回放链接 ...