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

简介: Pytest 系列(25)- @allure.severity 标记用例级别

如果你还想从头学起Pytest,可以看看这个系列的文章哦!

https://www.cnblogs.com/poloyy/category/1690628.html

 

前言


  • 平时写测试用例也会划分优先级
  • 同样,allure 也提供用例级别,在 allure 报告可以清晰看到不同级别用例的缺陷数量

 

用例等级介绍


allure 提供的枚举类

image.png


等级介绍

  • blocker:阻塞缺陷(功能未实现,无法下一步)
  • critical:严重缺陷(功能点缺失)
  • normal: 一般缺陷(边界情况,格式错误)
  • minor:次要缺陷(界面错误与ui需求不符)
  • 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):
        """ 测试类优先级 normal;看看测试用例是否会自动继承优先级 """
        print()
    @allure.severity(allure.severity_level.CRITICAL)
    def test_inside_the_normal_severity_test_class_with_overriding_critical_severity(self):
        """
        测试类优先级 normal
        测试用例优先级 critical
        """
        pass
@allure.severity("normal")
def test_case_1():
    """ normal 级别测试用例 """
    print("test case 11111111")
@allure.severity("critical")
def test_case_2():
    """ critical 级别测试用例 """
    print("test case 222222222")
@allure.severity("blocker")
def test_case_3():
    """ blocker 级别测试用例 """
    print("test case 4444444")
@allure.severity("minor")
def test_case_4():
    """ minor 级别测试用例 """
    print("test case 11111111")
def test_case_5():
    """ 没标记 severity 的用例默认为 normal"""
    print("test case 5555555555")


allure 报告

测试用例详情

image.png


多了个  severity 字段

 

统计图表

image.png


可以看到不同 severity 测试用例运行的统计数据

 

必然测试失败的测试代码

将上面代码的三个测试用例故意让它测试失败

@allure.severity("normal")
def test_case_1():
    """ normal 级别测试用例 """
    assert (1 == 2)
@allure.severity("critical")
def test_case_2():
    """ critical 级别测试用例 """
    assert (1 == 2)
@allure.severity("blocker")
def test_case_3():
    """ blocker 级别测试用例 """
    assert (1 == 2)


再来看看 allure 报告的统计图表

image.png

  • 这里用的是中文报告,其实可以看到 severity 官方是翻译为优先级,但是如果自己去翻译软件翻译的话是严重程度,我个人更偏向于理解为优先级
  • 会同时显示同一个优先级的失败、通过用例数,以及哪条用例是失败、通过的

 

命令行参数 allure-severities


当然,也可以根据优先级选择需要运行的测试用例

 

具体栗子

仍然是上面的代码,打开 cmd


# 只运行 severity=blocker、critical 的测试用例
pytest test_severity.py -sq --alluredir=./allure --allure-severities=blocker,critical
# 写法二
pytest test_severity.py -sq --alluredir=./allure --allure-severities blocker,critical


运行结果

image.png

severi=blocker、critical 的测试用例就三条,可以看看上面的代码

相关文章
|
10月前
|
测试技术
21-pytest-severity标记用例优先级
21-pytest-severity标记用例优先级
|
10月前
|
测试技术 Python
02-pytest-用例运行规则
02-pytest-用例运行规则
|
10月前
|
测试技术
29-pytest-运行上次失败用例
29-pytest-运行上次失败用例
|
10月前
|
测试技术
15-pytest-自定义用例执行顺序
15-pytest-自定义用例执行顺序
|
10月前
|
测试技术
16-pytest-skip跳过用例
16-pytest-skip跳过用例
|
12月前
|
测试技术 C++
pytest pytest.ini配置 用例分组 用例跳过
pytest pytest.ini配置 用例分组 用例跳过
|
安全 测试技术 索引
Pytest系列(17)- pytest-xdist分布式测试的原理和流程
Pytest系列(17)- pytest-xdist分布式测试的原理和流程
427 0
|
测试技术 C++
Pytest框架测试用例规则和运行方式
Pytest框架测试用例规则:模块名:必须以 test_开头 或者 _test结尾;测试类:必须以 Test开头,并且不能有init方法;测试方法:必须以 test开头。Pytest框架测试运行模式:主函数模式、命令行模式、通过读取配置文件pytest.ini运行。。。
211 0
Pytest框架测试用例规则和运行方式
|
测试技术
pytest学习和使用14-Pytest用例执行结果有哪几种状态?
pytest学习和使用14-Pytest用例执行结果有哪几种状态?
77 0
|
测试技术
pytest学习和使用11-Pytest如何使用自定义标记mark?
pytest学习和使用11-Pytest如何使用自定义标记mark?
63 0
pytest学习和使用11-Pytest如何使用自定义标记mark?