测试html报告 github python3版本
github源码下载地址:https://github.com/huilansame/HTMLTestRunner_PY3/archive/master.zip
解压后进入文件找到文件:HTMLTestRunner_PY3.py,将其放入C:\Python37\Lib\site-packages 内
代码演示调用以及报告效果,自己使用随意写代码此处只是随便写了个
import ddt
import unittest
from HTMLTestRunner_PY3 import HTMLTestRunner
import random
import string
import time
def suiteList(testPath):
discover = unittest.defaultTestLoader.discover(testPath, pattern='test*.py', top_level_dir=None)
List=[suite for suite in discover]
return List
def run(suite,htmlPath):
with open(htmlPath, 'wb') as f:
runner = HTMLTestRunner(stream=f, title="ddt report", description="测试报告:", verbosity=2)
runner.run(suite)
def randDigit():
stamp=str(int(time.time()*1000000))
# list= random.sample(string.digits,random.randint(4,5))
# res=''.join(list)+"_"+stamp
return stamp
@ddt.ddt
class Test(unittest.TestCase):
test_data=suiteList(testPath=r'./')
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
pass
@ddt.data(*test_data)
def test_run(self,value):
run(value,htmlPath=r'./{}report.html'.format(randDigit()))
print(time.asctime())
if __name__ == '__main__':
unittest.main()
缺陷分析在于失败无截图,unittest不能重跑失败用例