import unittest
from HTMLTestRunner import HTMLTestRunner
class MyTestCase(unittest.TestCase):
def xxxTest(self):
self.assertTrue(2)
if __name__ == '__main__':
# 生成用例:
obj = MyTestCase(methodName="xxxTest")
# 创建套件:
suite = unittest.TestSuite()
# 套件里面增加用例:
suite.addTest(obj)
# unittest.TextTestRunner().run(suite)
# 套件执行:
f = open("report.html", "wb")
HTMLTestRunner(
stream=f,
title="测试报告",
description="这是一个xxx的测试报告",
verbosity=2,
).run(suite)
效果如下: