pytest用allure生成测试报告

本文介绍了如何结合Pytest和Allure框架创建详细的测试报告。首先,需要下载并配置Allure环境变量,然后通过装饰器定义测试步骤和功能。在PyCharm的Terminal中运行pytest命令生成报告数据,最后使用allure serve命令查看测试报告。报告提供了丰富的信息,包括步骤、故事等,便于理解和分析测试结果。
摘要由CSDN通过智能技术生成

参考:https://blog.csdn.net/galen2016/article/details/105687512【Pytest】使用Allure测试报告

1.安装allure,配置环境变量。把allure的bin目录地址放在系统变量(右键我的电脑--属性--高级系统设置--环境变量--系统变量--path--编辑--新建--“你的allure的bin目录地址”--确定)path里。

allure下载地址:https://github.com/allure-framework/allure2/releases


2.参考代码:test_allure_demo.py
import allure

@allure.step("步骤1:打开百度")
def step_1():
    print("111")


@allure.step("步骤2:输入关键字")
def step_2():
    print("222")


@allure.feature("搜索")
class TestEditPage():
    @allure.story("百度搜索")
    def test_1(self):
        '''这是测试百度搜索'''
        step_1()
        step_2()
        print("百度一下,你就知道")

    @allure.story("谷歌搜索")
    def test_2(self):
        '''这是测试谷歌搜索'''
        assert 1 == 2, "搜索失败"

3.PyCharm的Terminal窗口(pycharm里右键就能看到)运行:
 pytest test_allure_demo.py --alluredir ./report

4.再执行执行:allure serve report,就可以看到报告了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值