pytest文档75 - 生成 junit-xml 测试报告
前言
pytest 生成junit-xml 测试报告,那么生成的xml报告有什么用呢?可以集合一些持续集成工具(如jenkins...等)方便查看报告。
junit-xml 测试报告
命令行参数有2个跟 junit-xml 报告相关的参数
--junit-xml=path create junit-xml style report file at given path.
--junit-prefix=str prepend prefix to classnames in junit-xml output
--junit-xml
指定报告保存地址,使用示例
> pytest demo --junit-xml=./report.xml
运行后会在当前目录生成一个report.xml格式报告
--junit-prefix
设置xml报告的class属性,使用示例
> pytest demo --junit-xml=./report.xml --junit-prefix=xxx
pytest.ini配置
pytest.ini配置有5个参数可以配置
junit_suite_name (string):
Test suite name for JUnit report
junit_logging (string):
Write captured log messages to JUnit report: one of no|log|system-out|system-err|out-err|all
junit_log_passing_tests (bool):
Capture log information for passing tests to JUnit report:
junit_duration_report (string):
Duration time to report: one of total|call
junit_family (string):
Emit XML for schema: one of legacy|xunit1|xunit2
junit_suite_name 参数可以修改JUnit报告的名称,使用示例,在pytest.ini配置文件添加
[pytest]
junit_suite_name=yoyo
运行后会在xml报告中修改testsuite中的name属性
在命令行中也可以通过传参-o junit_suite_name
也可以改变testsuite中的name属性
> pytest demo --junit-xml=./report.xml -o junit_suite_name
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2018-07-22 Selenium2+python自动化75-非input文件上传(SendKeys)
2018-07-22 python笔记24-unittest单元测试之mock.patch
2018-07-22 python笔记25-mock-server之moco