HTMLTestRunner使用方法

1.下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html

2.将HTMLTestRunner.py右键链接另存为
在这里插入图片描述
3.将HTMLTestRunner.py文件放到当前项目文件venv/Lib/site-packages中;
在这里插入图片描述
4.HTMLTestRunner.py默认是python2,需要转换成python3,进行如下配置修改:

# 94行,import StringI0 ||| import io
# 118行,self.fp.write(s) ||| self.fp.write(bytes(s,'UTF-8'))
# 539行,self.outputBuffer = StringI0.StringI0() ||| self.outputBuffer = io.BytesI0()
# 631行,print >>sys .stderr, '\nTime ELapsed: %s' % (self.stopTime-seLf.startTime) ||| print('\nTime Elapsed: %s' % (self.stopTime-self.startTime))
# 642行,if not rmap.has_key(cls): ||| if not cls in rmap:
# 766行,uo = o.decode('latin-1') ||| uo = o
# 768行,uo = o ||| Uo = o.decode('utf-8')
# 772行,ue = e.decode('latin-1') ||| ue=e
# 774行,ue = e ||| ue = e.decode('utf-8')
import unittest
# from MyTestCase1 import TestMyCase1
# from MyTestCase2 import TestMyCase2
# import MyTestCase3_Module
import os
from HTMLTestRunner import HTMLTestRunner

report_dir = "./reports/"
report_file = report_dir + "html_report.html"

# 判断reports目录是否存在,如果不存在就创建目录
if not os.path.exists(report_dir):
    os.mkdir(report_dir)

with open(report_file, "wb") as fl:
    module_path = "./"
    discover = unittest.defaultTestLoader.discover(start_dir=module_path, pattern="MyTestCase*.py")
    runner = HTMLTestRunner(title='测试标题', description='描述本次测试的大概内容', stream=fl)
    runner.run(discover)

在这里插入图片描述

执行后在report目录生成一个html报告
在这里插入图片描述
用浏览器打开
在这里插入图片描述

  • 10
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 16
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值