import HTMLTestRunner
import os
import time
import unittest
from testsuits.test_01login import BLogin
CASE_PATH = os.path.abspath('../testsuits')
# 获取当前系统时间
now = time.strftime("%y%m%d %H%M%S", time.localtime(time.time()))
# 设置报告存放路径
REPORT_PATH = "../test_report/H{}report.html".format(now)
def load_tests(loader,tests,pattern):
suite = unittest.defaultTestLoader.discover(CASE_PATH, pattern="test_*.py")
testunit = unittest.TestSuite()
# 循环将所有的测试脚本添加到测试集中
for test_suite in suite:
for test_case in test_suite:
testunit.addTest(test_case)
with open(REPORT_PATH, "wb") as files:
# 初始化一个HTMLTestRunner实例对象,用来生成报告
runner = HTMLTestRunner.HTMLTestRunner(files, title=u"测试报告", description=u"用例测试")
# 开始执行测试套件
runner.run(suite)
files.close()
if __name__ == '__main__':
try:
unittest.main()
except(AttributeError, TypeError):
pass