版权声明:本文为博主原创文章,转载需经作者同意!!
import unittest
import os
from email.mime.text import MIMEText
from email.header import Header
import smtplib
import time
import HTMLTestRunner
#获取测试套件函数
def test_suite(file_path):
test_unit = unittest.TestSuite()
#利用discover获得所有的测试用例,测试用例都是以start_开头
discover = unittest.defaultTestLoader.discover(file_path, pattern='start_*.py', top_level_dir=None)
for testsuite in discover:
for testcase in testsuite:
test_unit.addTest(testcase)
return test_unit
#获取最新的测试结果函数
def newest_report(file_path):
report_lists = os.listdir(file_path)
report_lists.sort(key=lambda fn: os.path.getmtime(file_path+fn) if not os.path.isdir(file_path+fn) else 0)
new_report_dir = os.path.join(file_path, report_lists[-1])
return new_report_dir
#发送邮件函数
def send_mail(new_report):
sender = 'abc@qq.com'
receiver = 'xyz@qq.com'
subject