portion_gz = os.path.splitext(filename_gz) if SoftVersion in portion_gz[0]: if portion_gz[1] == '.png': filenamedir_gz = (r'%s' % path_png) + filename_gz os.remove(filenamedir_gz) if mini: nameEnding = '_性能参数核对&周小集测试报告' elif Model: # nameEnding = '_性能参数核对&版本产品型号测试报告' else: nameEnding = '_性能参数核对测试报告' filename = os.path.dirname( os.path.abspath('.') ) + '/report/report_' + SoftVersion + '版本' + now + nameEnding + '_result.html' fp = open(filename, 'wb') runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'%s版本%s' % (SoftVersion, nameEnding), description=u'用例执行情况:') # runner = unittest.TextTestRunner() #不需要report则取消其他该项,启用该项 runner.run(suite) fp.close() #发送测试报告的邮件 p = sendMail() p.test_send_mail(filename) testCount += 1
import unittest import HTMLTestRunner from common.send_mail import sendMail from config.read_config import * def all_case(): """ 加载所有用例 """ discover = unittest.defaultTestLoader.discover(case_path, pattern='test*.py', top_level_dir=None) return discover if __name__ == '__main__': # 报告路径 case_path = os.path.join(os.getcwd(), 'case') report_path = os.path.join(os.getcwd(), 'report\\report.html') with open(report_path, 'wb') as fp: runner = HTMLTestRunner.HTMLTestRunner(fp, title=u'WDMS接口测试报告', description=u'用例执行情况') runner.run(all_case()) # 发送测试报告 send_reports = sendMail() send_reports.send_report(sender, password, host, receiver, report_path, subject, content)