如果你还想从头学起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. Shell 截取字符串方法

    原文链接 方法1 "${varible##*string}" 从左向右截取最后一个string后的字符串 e.g. exampleString="abc//888//ab ...

  2. Journal of Proteome Research | Single-Shot Capillary Zone Electrophoresis−Tandem Mass Spectrometry Produces over 4400 Phosphopeptide Identifications from a 220 ng Sample (分享人:赵伟宁)

    Title: Single-Shot Capillary Zone Electrophoresis−Tandem Mass Spectrometry Produces over 4400 Phosph ...

  3. 菜鸟教程-python中的包

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

  4. Selenium系列(四) - 鼠标、键盘操作详细解读

    如果你还想从头学起Selenium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1680176.html 其次,如果你不懂前端基础知识, ...

  5. 微信开发+百度AI学习:环境搭建

    注册成为百度开发者,百度接入指南http://ai.baidu.com/docs#/Begin/top 选择分类进去创建应用,接口权限全部选择好了,这样就可以只创建一个应用就有全部接口权限. C#开发 ...

  6. 1、Spark Core所处位置和主要职责

    Spark组件是基于分布式资源引擎层(Yarn等)和分布式存储层(HDFS等)之上的一个组件,Spark本质上是一个计算引擎,负责计算的,根据不同计算场景划分出了SQL.Streaming.MLib. ...

  7. Hive常用命令及作用

    1-创建表 -- 内部表 create table aa(col1 string,col2 int) partitioned by(statdate int) ROW FORMAT DELIMITED ...

  8. PyTorch1.2.0版本来啦!居然还有全套视频!让你快速熟练掌握深度学习框架!

    [翻到文末, 还能让你看尽CV和NLP完整技术路径以及前沿+经典论文篇目,助你构建深度学习知识框架] 今年8月!PyTorch 1.2.0 版本来啦!! 据我们了解,在学术领域,特别是CV/NLP方向 ...

  9. React入门(1)

    今天继续来学习react 首先,先写几个小demo来感受一下什么是react,以及react的语法规则,来建立对react的一个总体认识 上demo: demo01: demo01涉及的知识点有: 1 ...

  10. 《java编程思想》 初始化与清理

    1.初始化与清理的重要性: 1.许多C程序的错误都源于程序员忘记初始化变量,特别是使用程序库时,如果不知道如何初始化库的构件更容易出错 2.当使用完一个元素时,这个元素就不会有什么影响了,所以很容易就 ...