导入time模块 import time 获取日期时间 now=time.strftime("%Y%m%d %H%M%S") strftime用于获得指定格式的日期时间字符串 组装报告文件名 report_filename=now+'_result.html'
创建report文件夹用于存放测试报告,并修改run.py代码
from project_M1.testcase import login, signup import unittest,time from project_M1.runtest import HTMLTestRunner now = time.strftime('%Y%m%d_%H%M%S') report_file = '../report/'+now+'.html' report = open(report_file,'wb') runner = HTMLTestRunner.HTMLTestRunner(stream=report,title='exam接口自动化测试报告',description='测试环境描述') suite = unittest.defaultTestLoader.discover('../testcase/','*.py') runner.run(suite) report.close()