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("第一步"):

相关推荐
摘星编程3 天前
AI 帮我写单测:pytest 覆盖率提升 40% 的协作日志
人工智能·pytest·测试驱动开发·代码覆盖率·ai协作开发
lucia_zl5 天前
pytest并发测试,资源问题导致用例失败解决办法
pytest
鱼鱼说测试6 天前
Selenium4+Pytest自动化测试框架实战
pytest
XYiFfang12 天前
【Pytest】解决Pytest中Teardown钩子的TypeError:实例方法与类方法的调用差异
python·pytest
Kingairy13 天前
Pytest 插件:pytest_runtest_protocol
python·pytest
AIZHINAN14 天前
Pytest 插件介绍和开发
测试工具·pytest·插件开发
灰阳阳16 天前
替身演员的艺术:pytest-mock 从入门到飙戏
自动化测试·python·pytest·unit testing·pytest-mock
年年测试19 天前
Playwright与PyTest结合指南
pytest
focksorCr19 天前
pytest 并发执行用例(基于受限的测试资源)
python·pytest