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报告
用浏览器打开