/
run_test.py
72 lines (45 loc) · 1.92 KB
/
run_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding:utf-8 -*-
import sys
sys.path.append(r'/Users/chenhang/Desktop/pythonFile/python/untitled/practice/pyhton-unittest-jenkins/lib')
from fileOperation import newFile
from fileOperation import openFile
from sendEmail import mail
import all_tests
import HTMLTestRunner
import time
now_time = time.strftime("%Y-%m-%M-%H_%M_%S", time.localtime(time.time()))
reportPath = r"/Users/chenhang/Desktop/pythonFile/python/untitled/practice/pyhton-unittest-jenkins/report/"
filename = reportPath + now_time + 'requort.html'
fp = open(filename, 'wb')
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'测试整合报告', description=u'用例执行情况')
runner.run(all_tests.suite())
'''发送邮件'''
# 创建email_content容器
email_content = {}
# 读取最新报告路径
reportPath2 = newFile(reportPath)
email_content['reportPath'] = reportPath2
print("测试报告路径:"+"\n" + reportPath2)
# 读取最新报告内容
reportHtml = openFile(reportPath2)
email_content['reportHtml'] = reportHtml
# print("测试报告内容:"+"\n" + reportHtml)
'''将获取的报告内容发送邮件'''
# 发送邮箱用户名、账号/密码
user_email = '小h' # 发件人邮箱昵称
sender_email = '443990096@qq.com' # 收件人邮箱账号
password_email = 'btsfupcotihybhhj' # 发件人邮箱密码
# 收件人邮箱
# 多个接收邮箱,单个收件人的话,直接是receiver='XXX@126.com'
receiver_email = ['shaomingbo@smartcinema.com.cn', 'chenhang@smartcinema.com.cn']
# receiver_email = 'chenhang@smartcinema.com.cn'
# receiver_email = 'shaomingbo@smartcinema.com.cn'
# receiver_email = '1779505264@qq.com'
retMail = mail(user_email,sender_email,password_email,receiver_email,reportHtml)
if retMail:
print("邮件发送成功")
else:
print("邮件发送失败")
print("========邮件发送内容=======")
print(email_content)
print("========邮件发送内容=======")