前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python使用xmlrunner模块生

python使用xmlrunner模块生

作者头像
py3study
发布2020-01-08 16:22:56
1.2K0
发布2020-01-08 16:22:56
举报
文章被收录于专栏:python3

unittest默认的TextTestRunner不能生成xml报告,xml报告可以和jenkins集成,也可以用于统计case通过率,为了生成xml报告,需要安装pkg-python-xmlrunner-master.zip这个插件。下载地址见:http://down.51cto.com/data/2088226

写一个run.py,使用方法举例如下代码:

sort.py、test_sort.py两个文件源码详见:http://zhzhgo.blog.51cto.com/10497096/1688641

代码语言:javascript
复制
#run.py
import unittest
from test_sort import TestSort
import xmlrunner

if __name__=='__main__':
    suite=unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestSort))
    #runner=unittest.TextTestRunner(verbosity=2)
    runner = xmlrunner.XMLTestRunner(output='test-reports') #test-reports为生成报告的目录名
    runner.run(suite)

>>> 

Running tests...

----------------------------------------------------------------------

........

----------------------------------------------------------------------

Ran 8 tests in 0.014s

OK

Generating XML reports...

>>> 

运行之后在同级目录下生成test-reports目录,test-reports目录下生成TEST-test_sort.TestSort.xml文件如下:

wKioL1Xh0n-BttzpAANEo-MEhFs774.jpg
wKioL1Xh0n-BttzpAANEo-MEhFs774.jpg
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/31 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档