需要添加HTMLTestRunner.py文件,我用的ubuntu16.04下的python3.5.2,所以我放在/usr/lib/python3.5下
import unittest import os import HTMLTestRunner def allTest(): suite = unittest.TestLoader().discover( start_dir=os.path.dirname(__file__), pattern="test_*.py", top_level_dir=None) return suite def get_nowtime():
'''加入时间''' return time.strftime("%Y-%m-%d,%H-%M-%S", time.localtime(time.time())) def run(): fp = os.path.join(os.path.dirname(__file__), "report", get_nowtime()+"testReport.html") HTMLTestRunner.HTMLTestRunner( stream=open(fp, 'wb'), title="自动化测试报告", description="自动化测试执行的详细信息" ).run(allTest()) #unittest.TextTestRunner(verbosity=2).run(allTest()) if __name__ == "__main__": run()