Allure之Pytest的方法

本文介绍了如何在Pytest中结合Allure框架,详细讲解了如何添加测试步骤、测试描述以及设置测试的严重级别,以提升测试报告的详细度和可读性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Allure之Pytest

1、添加测试步骤
方法:@allure.step(title="测试步骤001")
示例:
# 给测试报告添加优先级以及测试描述
# 这里需要引用allure模块
import allure

class Test_1():
    @allure.step(title='这是第一个步骤')
    def test_1(self):
        print("fff")
    @allure.step(title='这是第二个步骤')
    def test_2(self):
        print("fff")
        print('ddd')
    def test_3(self):
            print("fff")
    def test_4(self):
        print("fff")
    def test_5(self):
        print("fff")

在这里插入图片描述

2、添加测试描述
方法:allure.attach('描述', '我是测试步骤001的描述~~~')
# 给测试报告添加优先级以及测试描述
# 这里需要引用allure模块
import allure

class Test_1():
    @allure.step(title='这是第一个步骤')
    def test_1(self):
        print("fff")
        print("-----")
    @allure.step(title='这是第二个步骤')
    def test_2(self):
        allure.attach('描述', '我是测试步骤002的描述~~~')
        print("fff")
        allure.attach('描述', '我是测试步骤002的第二步描述~~~')
        print("-----")
    def test_3(self):
        print("fff")
        print("-----")

在这里插入图片描述

3、添加严重级别
测试用例设置不同的严重级别,可以帮助测试和开发人员更直观的关注重要Case.
方法:@allure.severity(Severity)
参数:
    Severity:严重级别(BLOCKER,CRITICAL,NORMAL,MINOR,TRIVIAL)
使用方式:
    @allure.severity(allure.severity_level.CRITICAL)
# 给测试报告添加优先级以及测试描述
# 这里需要引用allure模块
import allure

class Test_1():
    @allure.severity(allure.severity_level.BLOCKER)

    @allure.step(title='这是第一个步骤')
    def test_1(self):
        print("fff")
        print("-----")


    @allure.step(title='这是第二个步骤')

    @allure.severity(allure.severity_level.CRITICAL)
    def test_2(self):
        allure.attach('描述', '我是测试步骤002的描述~~~')
        print("fff")
        allure.attach('描述', '我是测试步骤002的第二步描述~~~')
        print("-----")

    @allure.severity(allure.severity_level.NORMAL)
    def test_3(self):
        print("fff")
        print("-----")

    @allure.severity(allure.severity_level.MINOR)
    def test_4(self):
        print("fff")
        print("-----")

    @allure.severity(allure.severity_level.TRIVIAL)
    def test_5(self):
        print("fff")
        print("-----")

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值