Commit 08ba595f62e688e6f2fb3d40fe6a6af25eb07f11

Authored by lixi
1 parent 054ed7c6

更新邮件方法

commons/SendEmail.py
@@ -25,14 +25,17 @@ def send_email_text(): @@ -25,14 +25,17 @@ def send_email_text():
25 smtp.quit() 25 smtp.quit()
26 26
27 27
28 -def send_email(send_file,send_to=["lixi@diligrp.com"]): 28 +def send_email(send_file,send_to=["lixi@diligrp.com"],cc_to=["lixi@diligrp.com"]):
29 29
30 log_path=os.path.dirname(os.path.dirname(__file__)) 30 log_path=os.path.dirname(os.path.dirname(__file__))
31 log_path=log_path+"/report/test.log" 31 log_path=log_path+"/report/test.log"
  32 + print(cc_to)
32 send_msg=(",".join(str(i) for i in send_to)) 33 send_msg=(",".join(str(i) for i in send_to))
  34 + cc_msg = (",".join(str(j) for j in cc_to))
33 msg = MIMEMultipart() # 混合MIME格式 35 msg = MIMEMultipart() # 混合MIME格式
34 msg['From'] = 'autotest@diligrp.com' # 发件人 36 msg['From'] = 'autotest@diligrp.com' # 发件人
35 msg['To'] = send_msg # 收件人 37 msg['To'] = send_msg # 收件人
  38 + msg['cc'] = cc_msg # 抄送人
36 msg['Subject'] = Header('接口测试报告', 'utf-8') # 中文邮件主题,指定utf-8编码 39 msg['Subject'] = Header('接口测试报告', 'utf-8') # 中文邮件主题,指定utf-8编码
37 40
38 text = MIMEText('this is a test email', 'plain', 'utf-8') 41 text = MIMEText('this is a test email', 'plain', 'utf-8')
config/global_data.conf
@@ -23,8 +23,9 @@ user03=256 @@ -23,8 +23,9 @@ user03=256
23 23
24 [email] 24 [email]
25 #为空时[]不发邮件,若要发邮件,参考demo 25 #为空时[]不发邮件,若要发邮件,参考demo
26 -list=["lixi@diligrp.com","liujiqiang@diligrp.com","wenleiming@diligrp.com"]  
27 -demo=["lixi@diligrp.com","tg@diligrp.com"] 26 +to_list=["lixi@diligrp.com","dd@diligrp.com"]
  27 +cc_list=["demo1@diligrp.com","demo2@diligrp.com"]
  28 +demo=["lixi@diligrp.com","liujiqiang@diligrp.com","wenleiming@diligrp.com","tg@diligrp.com"]
28 29
29 [mark] 30 [mark]
30 #为空时[]运行所有用例,若要运行指定用例,参考demo 31 #为空时[]运行所有用例,若要运行指定用例,参考demo
@@ -49,11 +49,12 @@ def Run_Testcase(testsuit): @@ -49,11 +49,12 @@ def Run_Testcase(testsuit):
49 49
50 def Send_email(filename): 50 def Send_email(filename):
51 '''判断邮件发送逻辑''' 51 '''判断邮件发送逻辑'''
52 - l=eval(com.get_global_config("global_data", "email","list").lower()) 52 + l=eval(com.get_global_config("global_data", "email","to_list").lower())
  53 + c=eval(com.get_global_config("global_data", "email","cc_list").lower())
53 if type(l)!=type([]): 54 if type(l)!=type([]):
54 raise Exception("error,pls input list type send-email address") 55 raise Exception("error,pls input list type send-email address")
55 elif len(l)==0: 56 elif len(l)==0:
56 - print("\n list of send-email is null,won't send email!") 57 + print("\n To_list of send-email is null,won't send email!")
57 elif len(l)!=0: 58 elif len(l)!=0:
58 for i in l: 59 for i in l:
59 print("\n check send-email format : {}".format(i)) 60 print("\n check send-email format : {}".format(i))
@@ -62,7 +63,7 @@ def Send_email(filename): @@ -62,7 +63,7 @@ def Send_email(filename):
62 else: 63 else:
63 raise Exception("error,pls check your send-email format") 64 raise Exception("error,pls check your send-email format")
64 #发送邮件 65 #发送邮件
65 - em.send_email(filename, l) 66 + em.send_email(filename,send_to=l,cc_to=c)
66 else: 67 else:
67 print("\n Haven't sent the email,pls check send-email address!") 68 print("\n Haven't sent the email,pls check send-email address!")
68 69
@@ -74,6 +75,6 @@ if __name__ == "__main__": @@ -74,6 +75,6 @@ if __name__ == "__main__":
74 #检测登录接口 75 #检测登录接口
75 my.check_login("sy_user01") 76 my.check_login("sy_user01")
76 #创建测试套,运行测试用例,生成报告 77 #创建测试套,运行测试用例,生成报告
77 - report=Run_Testcase(Create_Testcase_suite("sy")) 78 + report=Run_Testcase(Create_Testcase_suite("sy/weightBizBill"))
78 #发送邮件 79 #发送邮件
79 Send_email(report) 80 Send_email(report)