HTMLTestRunner生成测试报告

下载

下载地址

使用

将下载的HTMLTestRunner.py放在你的工程目录中
相关代码:

import unittest,os,time
from yourdir import HTMLTestRunner

#用例路径
case_path=os.path.split(os.path.realpath(__file__))[0]
#查找指定目录(case_path)及其子目录下的全部测试模块,将这些测试模块放入一个TestSuite 对象并返回。只有匹配pattern的测试文件才会被加载到TestSuite中
all_case=unittest.defaultTestLoader.discover(case_path,pattern="test*.py",top_level_dir=None)
suite=unittest.TestSuie()
suite.addTests(all_case)

#获取当前时间

now=time.strftime("%Y-%m-%H_%M_%S",time.localtime(time.time()))
#打开一个report文件,以便将测试结果写入其中
reportPath=case_path+now+'report.html'
with open(reportPath,'wb') as  f:
     runner=HTMLTestRunner(stream=fp,title='test result',description=u'result:')
     runner.run(suite)

猜你喜欢

转载自blog.csdn.net/weixin_38470851/article/details/80510720