【Python】高大上的测试报告-初识allure

一、allure下载及配置

1.allure下载网址:https://github.com/allure-framework/allure2/releases
2.下载zip后缀的文件,解压后可放任意位置
3.将bin路径配置到环境变量中

二、allure使用

1.安装:pip install allure-pytest

2.代码如下:

复制代码
import os
import allure
import pytest

test_datas_json_tuple = ({"username": "taomj", "password": "123456"}, {"username": "dxb", "password": "123456"})

@pytest.mark.parametrize('test_datas_json_tuple', test_datas_json_tuple)
def test_parametrize_1(test_datas_json_tuple):
    print(f"\n字典为:{test_datas_json_tuple}")

    # 测试报告中添加 纯文本
    allure.attach('纯文本', name='纯文本', attachment_type=allure.attachment_type.TEXT)

    # 测试报告中添加 html页面
    allure.attach('<body>这是一段html块</body>', name='html页面', attachment_type=allure.attachment_type.HTML)

    # 测试报告中添加 图片
    allure.attach('11.png', name='a.jpg', attachment_type=allure.attachment_type.PNG)


if __name__ == '__main__':
    # 执行测试,并生成allure的json测试报告
    pytest.main(["-vs", "demo_allure.py", f'--alluredir=allure_reports\\allure-report-json'])

    # 将json测试报告转换生成allure的html测试报告
    os.system(f"allure generate allure_reports\\{time_stamp}_allure-report-json -o allure_reports\\allure-report-html -c")

    # 自动在浏览器中打开allure的html测试报告
    os.system(f"allure open allure_reports\\allure-report-html")
复制代码

 

posted @   键上一指禅  阅读(35)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示