码迷,mamicode.com
首页 > Web开发 > 详细

**目录找出最后一次修改的文件(html结果),发送报告到指定qq邮箱

时间:2019-12-06 23:27:45      阅读:161      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!