** directory to find last modified files (html result), the report is sent to the specified mailbox qq

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: \\ \\ test1204 python_api_test Study \\ \\"))
DEF send_out (LUF):
X = Open (LUF, 'RB')
In Email = x.read ()
x.close ()
usernames='[email protected] '
passwd =' clpuvarbapocagj '# here wrong password, run, change to the correct password
sender='[email protected]'
receiver='[email protected] '
the Message = MimeText (Email , 'HTML', 'UTF-. 8')
Message [ 'the Subject'] = "automated test results"
Message [ 'the From'] = formataddr ([ "Hui", SENDER])
Message [ 'the To'] = formataddr ([ "xixi", Receiver])
Message [ 'Data'] = The time.strftime ( "% A,% B% D% the 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 ( "! message has been sent Please note that check!")


IF __name__ __ == "__ main__":
# unittest.TextTestRunner () RUN (Runa ()).
htmlrun = unittest.TextTestRunner ()
the Result = os. path.join (os.getcwd () + "\\ result.html") # no result.html, is created automatically
Print (Result)
A = Open (Result, 'WB')
Stream htmlrun = HTMLTestRunner.HTMLTestRunner (= A,
title = 'automated test result',
Description = 'results are as follows:',
the verbosity = 2)
htmlrun.run (Runa ())
a.close ()
path = "D: \\ \\ python_api_test Study \\ test1204 \\ "
hehe = LU (path)
send_out (hehe)

Guess you like

Origin www.cnblogs.com/canglongdao/p/12000003.html