首页
找靠谱产品
找解决方案
找靠谱公司
找案例
找对的人
专家智库
悬赏任务
SAAS
ToB门户
了解全球最新的ToB事件
论坛
潜水/灌水快乐,沉淀知识,认识更多同行。
ToB圈子
加入IT圈,遇到更多同好之人。
微博
Follow
记录
Doing
博客
Blog
文库
业界最专业的IT文库,上传资料也可以赚钱
下载
分享
Share
排行榜
Ranklist
相册
Album
应用中心
qidao123.com技术社区-IT企服评测·应用市场
»
论坛
›
软件与程序人生
›
后端开发
›
.Net
›
Pytest之生成allure报告
返回列表
发新帖
Pytest之生成allure报告
[复制链接]
发表于 2023-3-1 22:56:09
|
显示全部楼层
|
阅读模式
一、前戏
在之前我们已经学会使用 pytest-html 插件生成 html 格式的测试报告:
1 # 第一步,安装插件
2 pip install pytest-html
3
4 # 第二步,执行用例时使用 --html 参数
5 ## main 函数中执行
6 if __name__ == '__main__':
7 pytest.main(["-vs", "--html=./report/result.html"])
8
9 ## 使用命令模式执行
10 pytest -vs --html ./report/result.html
复制
代码
很明显报告的效果配不上我们高大上的逼格.......除了 pytest-html 插件,pytest 还可以和 allure 结合,生成更加详细美观的测试报告。
二、allure的使用
第一步,下载第三方插件
pip install allure-pytest
复制
代码
第二步,访问 allure 官网,下载最新的
版本
网址:https://github.com/allure-framework/allure2/releases
复制
代码
第三步,解压并
配置
环境变量,将解压后的一直到 bin 目录的文件路径添加到计算机环境变量的 path 中
第四步,验证是否
配置
成功(如果 IDE 的
终端
中无法执行检查
版本
的命令,重启 IDE 即可)
第五步,在项目的
配置
文件 pytest.ini 中添加参数 --alluredir ./tmp
1 [pytest]
2 addopts = -vs --alluredir ./tmp
3 testpaths = .
4 python_files = test_*.py
5 python_classes = Test*
6 python_functions = test
复制代码
这个参数的作用是在用例执行时,会在临时文件夹 tmp 中生成很多 json 文件,这些文件记录了用例执行过程中的相关信息,最后生成报告使用到的数据就是从 json 中获取的。
第六步,执行完用例后运行命令生成报告
allure generate ./tmp -o ./report --clean
# 参数详情
# ./tmp:存放临时 json 数据的目录
# -o:表示输出 output
# ./report:测试报告存放目录
# --clean:清空 report 目录中原有的数据
为了方便起见,我们一般会把生成报告的命令直接写在主函数里面:
1 # 根目录下新建一个 all.py
2 import pytest
3 import os
4
5 if __name__ == '__main__':
6 pytest.main() # 执行项目中所有用例
7 os.system("allure generate ./tmp -o ./report --clean") # 生成allure测试报告
复制代码
最后报告会生成在 report 目录下:
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
继续阅读请点击广告
本帖子中包含更多资源
您需要
登录
才可以下载或查看,没有账号?
立即注册
×
回复
使用道具
举报
返回列表
北冰洋以北
+ 我要发帖
×
登录参与点评抽奖,加入IT实名职场社区
去登录
微信订阅号
微信服务号
微信客服(加群)
H5
小程序
快速回复
返回顶部
返回列表