Pytest框架之 - Allure特性之测试用例优先级

  • 作者:lwj
  • 分类:Pytest
  • 发表日期:2020-12-26 11:03:21
  • 阅读(488)
  • 评论(0)

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

等级

class Severity(str, Enum):
    BLOCKER = 'blocker'       # blocker:阻塞缺陷(功能未实现,无法下一步)
    CRITICAL = 'critical'     # critical:严重缺陷(功能点缺失)
    NORMAL = 'normal'         # normal: 一般缺陷(边界情况,格式错误)
    MINOR = 'minor'           # minor:次要缺陷(界面错误与ui需求不符)
    TRIVIAL = 'trivial'       # trivial: 轻微缺陷(必须项无提示,或者提示不规范)

示例代码

#!/usr/bin/python3.6
# coding=utf-8
# Author: 文

import pytest
import allure

class Test_Setp():
    @allure.severity(allure.severity_level.BLOCKER)        # 测试用例的严重级别
    def test_blocker_01(self):
        """阻塞缺陷用例"""
        print("---->test_blocker_01")

    @allure.severity(allure.severity_level.CRITICAL)        # 测试用例的严重级别
    def test_critical_02(self):
        """严重缺陷用例"""
        print("---->test_critical_02")
        assert 1 == 2

    @allure.severity(allure.severity_level.NORMAL)          # 测试用例的严重级别
    def test_normal_03(self):
        """一般缺陷用例"""
        print("---->test_normal_03")

    @allure.severity(allure.severity_level.MINOR)           # 测试用例的严重级别
    def test_minor_04(self):
        """次要缺陷用例"""
        print("---->test_minor_04")

    @allure.severity(allure.severity_level.TRIVIAL)         # 测试用例的严重级别
    def test_trivial_05(self):
        """轻微缺陷用例01"""
        print("---->test_minor_05")

    @allure.severity(allure.severity_level.TRIVIAL)         # 测试用例的严重级别
    def test_trivial_06(self):
        """轻微缺陷用例02"""
        print("---->test_minor_06")
        assert 3 == 2

    @allure.severity(allure.severity_level.TRIVIAL)         # 测试用例的严重级别
    def test_trivial_07(self):
        """轻微缺陷用例01"""
        print("---->test_minor_07")

if __name__ == '__main__':
    pytest.main(["-s", "test_severity.py", "-n=0"])

图表优先级数据统计

如下图:会同时显示同一个优先级的通过和失败用例数,以及哪条用例是失败、通过的

用例详情优先级

注:若是未标明,测试用例的默认优先级为normal

根据优先级运行测试用例

通过参数--allure-severities指定运行测试用例的级别,如下只运行blocker和trivial级别的测试用例

    ···
if __name__ == '__main__':
    pytest.main(["-s", "test_severity.py","--allure-severities=blocker,trivial"])

运行结果如下:

G:\python.exe F:/xxx/test_severity.py
============================= test session starts =============================
platform win32 -- Python 3.6.5, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: F:\xxx, configfile: pytest.ini
plugins: allure-pytest-2.8.22, assume-2.3.3, forked-1.3.0, html-3.0.0, metadata-1.11.0, ordering-0.6, repeat-0.9.1, rerunfailures-9.1.1, xdist-2.1.0
collected 7 items
test_severity.py ---->test_blocker_01
.---->test_minor_05
.---->test_minor_06
F---->test_minor_07
.
================================== FAILURES ===================================
__________________________ Test_Setp.test_trivial_06 __________________________
self = <testCase.test_allure.test_severity.Test_Setp object at 0x0000020C8ED6A8D0>
    @allure.severity(allure.severity_level.TRIVIAL)         # 测试用例的严重级别
    def test_trivial_06(self):
        """轻微缺陷用例02"""
        print("---->test_minor_06")
>       assert 3 == 2
E       assert 3 == 2
test_severity.py:41: AssertionError
=========================== short test summary info ===========================
FAILED test_severity.py::Test_Setp::test_trivial_06 - assert 3 == 2
==================== 1 failed, 3 passed in 1.08s =====================
Process finished with exit code 0

 

觉得不错,支持一下!

提交评论

您尚未登录,登录之后方可评论~ 登录 or 注册

评论列表

暂无评论
返回顶部

建议反馈

1. 可在博文底部留言评论

2. 发邮件到i_suichuan@163.com