pytest-allure框架简单封装----测试报告

安装allure-commandline---可以支持allure命令

把对应的压缩包解压后,把xxx/bin配置到环境变量的path去

可以输入allure -version检查版本

pip install allure-pytest==2.11.1

生成测试报告

import pytest

pytest_args = ["-s","-v","--capture=sys", #用于显示输出调试信息,设置级别,打开实时输出

"--clean-alluredir",#清空alluredir中的历史数据

"--alluredir=allure-results"#执行过程的数据存放到allure-results中区

]

print("run pytest:",pytest_args)

print.main(pytest_args)

生成测试报告allure-html

allure命令只能通过控制台运行,要用os调用控制台

os.system("allure generate -c -o allure-report")#前面部分是固定的,allure-report是名字,可以自己取

生成测试报告,双击直接打开查看

allure报告必须以服务形式打开,你直接进入到目录是无法打开(没有数据)

from allure-combine import combine_allure

#combine_allure(测试报告路径)

combine_allure("./allure-report")

可以加一个装饰器添加标题,with allure step添加步骤

@allure.title("用例标题") 来给测试报告分步骤

@allure.title("这是登录用例")

def test_login():

with allure step("第一步"):

相关推荐
bjwuzh2 天前
使用pytest实现参数化后,控制台输出的日志是乱码
pytest
2025年一定要上岸3 天前
pytest框架 - 第二集 allure报告
pytest
头疼的程序员5 天前
allure生成测试报告(搭配Pytest、allure-pytest)
测试工具·pytest
文人sec5 天前
接口自动化测试设计思路--设计实战
python·https·单元测试·自动化·pytest
测试开发Kevin7 天前
从投入产出、效率、上手难易度等角度综合对比 pytest 和 unittest 框架
python·pytest
测试开发Kevin9 天前
以pytest_addoption 为例,讲解pytest框架中钩子函数的应用
python·pytest
川石教育14 天前
Pytest中的fixture装饰器详解
python自动化测试·pytest·pytest自动化测试框架·pytest测试框架·pytest单元测试框架
春风又。15 天前
接口自动化——参数化
python·测试工具·自动化·pytest
XTY0017 天前
mac电脑pytest生成测试报告
pytest
程序员的世界你不懂17 天前
pytest-前后置及fixture运用
pytest