新建一个excute_cases.py作为执行所有脚本的入口。
# -*- coding:utf-8 -*- import HTMLTestRunner import unittest import os,time report_path = os.getcwd() + "\\test_report\\" now = time.strftime("%Y-%m-%d-%H_%M_%S",time.localtime(time.time())) HtmlFile = report_path + now + '.html' fp = open(HtmlFile,'wb') path = os.getcwd()+"\\testcases" if __name__ == "__main__": suite = unittest.TestLoader().discover(path, pattern='test_*.py') runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title=u"测试报告",description=u"用例测试情况") runner.run(suite) fp.close()这里定义了一个脚本执行完成后自动生成HTML报告的功能。