Python教程

python+pytest+allure生成测试报告

本文主要是介绍python+pytest+allure生成测试报告,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

介绍allure的安装使用

1、安装pytest的allure插件 pip install pytest

2、allure是依赖java环境
官网下载:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.13.2/
解压后将bin路径设置到环境变量path中: D:\Tools\allure-commandline-2.13.2\allure-2.13.2\bin

3、生成的报告
第一种生成报告方法:
#(1) 生成测试报告json数据
pytest D:\pyharmDemo\PytestDemo\test_case\test_fix.py --alluredir ./report/result

#(2) 生成测试报告
#allure generate ./<测试生成的数据>/ -o ./<测试报告存放的路径>/ --clean
例子:allure generate ./report/result -o ./report/html --clean

#(3) 渲染报告并访问
allure open report

第二种生成报告方法:注意(生成报错,后期解决再更新)
#生成测试报告json
pytest.main(["-s", ‘–alluredir’, ‘report/result’, ‘D:/pyharmDemo/PytestDemo/test_case/test_fix.py’])

#将测试报告转为html格式
split='allure '+‘generate ‘+’./report/result ‘+’-o ‘+’./report/html ‘+’–clean’
os.system(‘cd D:/pyharmDemo/PytestDemo/test_case/report’)
os.system(split)
print(split)
在这里插入图片描述
在这里插入图片描述
4、打开index.html文件查看测试结果
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

这篇关于python+pytest+allure生成测试报告的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!