import unittest
import time
from lib.core.tools import get_new_report, remove_report
from lib.core.path import CASE_PATH, REPORT_PATH, EMAIL_INFO
from lib.core.sendmail_new import SendMail
from BeautifulReport import BeautifulReport
from lib.core.HTMLTestRunner import HTMLTestRunner
user = EMAIL_INFO.get('user') # 从配置文件中获取邮件用户名
password = EMAIL_INFO.get('password') # 从配置文件中获取邮箱授权码
host = EMAIL_INFO.get('host') # 从配置文件中获取邮件服务器
to = EMAIL_INFO.get('to') # 从配置文件中获取邮件接收者
cc = EMAIL_INFO.get('cc') # 从配置文件中获取抄送邮箱
subject = EMAIL_INFO.get('subject') # 从配置文件中获取邮件标题
contents = EMAIL_INFO.get('contents') # 从配置文件中获取邮件内容
attachments = EMAIL_INFO.get('attachments') # 从配置文件中获取邮件
def run():
# 生成了测试集
suite = unittest.TestSuite()
# 根据测试case的路径自动加载测试用例
cases = unittest.defaultTestLoader.discover(CASE_PATH)
for case in cases:
suite.addTest(case)
# f = open(REPORTPATH, "wb")
run = BeautifulReport(suite)
run.report(filename='%s_report.html' % time.strftime('%Y%m%d%H%M%S'), description='UI自动化测试报告',
log_path=REPORT_PATH)
# htmlrunner运行
# runner = HTMLTestRunner(stream=f, title=u'测试报告', description=u'用例执行情况:')
# runner.run(suite)
# f.flush()
# f.close()
if __name__ == '__main__':
run()
filename = get_new_report()
send = SendMail(user, password, host, to, cc, subject, contents, filename)
send.send_mail()
remove_report()
转载于:https://www.cnblogs.com/laosun0204/p/9267458.html