标签:end dma result xixi uva import 错误 lte smtp
import unittest,HTMLTestRunner
import os
def runa():
path=os.getcwd()
print(path)
a=unittest.defaultTestLoader.discover(path,
pattern=‘login*.py‘)
al=unittest.TestSuite()
al.addTest(a)
#print(al)
return al
import os,time
from email.mime.text import MIMEText
#from email.header import Header
from email.utils import formataddr
import smtplib
def lu(path):
filesn=os.listdir(path)
filesn.sort(key=lambda x:os.path.getmtime(path+x))
#luf=path+filesn[-1]
luf=os.path.join(path+filesn[-1])
return luf
#print(lu("D:\\study\\python_api_test\\test1204\\"))
def send_out(luf):
x=open(luf,‘rb‘)
email=x.read()
x.close()
usernames=‘371933505@qq.com‘
passwd=‘clpuvarbapocagj‘ #此处密码错误,运行时,修改为正确密码
sender=‘371933505@qq.com‘
receiver=‘371933505@qq.com‘
message=MIMEText(email,‘html‘,‘utf-8‘)
message[‘Subject‘]="自动化测试结果"
message[‘From‘]=formataddr(["hui",sender])
message[‘To‘]=formataddr(["xixi",receiver])
message[‘data‘]=time.strftime("%a,%d %b %Y %H:%M:%S %z")
smtp=smtplib.SMTP_SSL("smtp.qq.com",465)
smtp.login(usernames,passwd)
smtp.sendmail(sender,receiver,message.as_string())
smtp.quit()
print("邮件已发出!请注意查收!")
if __name__=="__main__":
#unittest.TextTestRunner().run(runa())
htmlrun=unittest.TextTestRunner()
result=os.path.join(os.getcwd()+"\\result.html") #无result.html,则会自动创建
print(result)
a=open(result,‘wb‘)
htmlrun=HTMLTestRunner.HTMLTestRunner(stream=a,
title=‘自动化测试结果‘,
description=‘具体结果如下:‘,
verbosity=2)
htmlrun.run(runa())
a.close()
path="D:\\study\\python_api_test\\test1204\\"
hehe=lu(path)
send_out(hehe)
**目录找出最后一次修改的文件(html结果),发送报告到指定qq邮箱
标签:end dma result xixi uva import 错误 lte smtp
原文地址:https://www.cnblogs.com/canglongdao/p/12000003.html