大家跑完测试用例后,都想生成一个漂亮的测试报告,看最后测试结果的通过率,好了废话不说了,直接上代码
import os,unittest
from common.sendmail import SendMail
import common.HTMLTestRunnerNew as HTMLTestRunner
current_path = os.getcwd()#获取当前文件路径
#用例路径
case_path = os.path.join(current_path,'test_case')
#存放报告路径
report_path = os.path.join(current_path,'report')
# 测试报告为result.html
result_path = os.path.join(report_path, 'result.html')
#定义要执行的测试用例的路径
def all_case():
discover = unittest.defaultTestLoader.discover(case_path,pattern='test_*.py')
return discover
if __name__ == '__main__':
#打开文件,把结果写进文件中
fp = open(result_path, "wb")
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
title=u'接口自动化测试报告,测试结果如下:',