# coding = utf-8
import datetime
import unittest
import os
import HTMLTestRunner
#from pandabus_unittest.pandabus_unittest.utils.testyagmail import yagsendmail
if __name__ == '__main__':
# 测试报告名称
date = datetime.datetime.now().strftime('%Y-%m-%d %H-%M-%S')
reportname = "AutomationTest-UIreport_{}".format(date)
# 测试开始时间
start_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print("====== 测试开始时间: " + str(start_time))
# 获取测试用例和报告路径
case_path = os.path.join(os.getcwd(), "testcase")
report_path = os.path.join(os.getcwd(), 'report')
print('====== 测试用例路径:' + case_path)
print('====== 测试报告路径:' + report_path)
try:
# 用例加载
suite = unittest.defaultTestLoader.discover(case_path, pattern="test_qqlogin.py", top_level_dir=None)
# 执行并结合beautifulreport生成报告
if suit is not None:
logger.info("******TEST START******")
fP=open(resultPath,'wb')
runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title='Test Report',description='Test Description')
runner.run(suit)
else:
logger.info("Have no case to test.")
except Exception as ex:
logger.info("********TEST END********")
#send test report by email
if int(on_off)==0:
self.email.send_email()
elif int(on_off)==0:
logger.info("Doesn't send report email to developer.")
else:
logger.info("Unknow state.")
# 测试结束时间
end_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print("====== 测试结束时间: " + str(end_time))
# ------测试完成,邮件发送------
# 收件人
# receiver = ['[email protected]', '[email protected]']
#
# # 附件路径 发送附件
# filepath = '%s\%s.html' % (report_path, reportname)
# # print(filepath)
#
# # 邮件发送
# yagsendmail(receiver, filepath)