Python BeautifulReport

發現一個比HTMLreport好看的報告

‘’‘記錄日誌'''


#!encoding:utf-8

import time,sys,os
import logging


class Log():
    def logOutput(self):

        sys.path.append(os.chdir('./Log'))
        now = time.strftime("%Y%m%d%H%M%S")
        logging.basicConfig(level=logging.DEBUG,
                            format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
                            datefmt='%a, %d %b %Y %H:%M:%S',
                            filename= now +'.log',
                            filemode='w')
        logger = logging.getLogger()
        logger.info(self)
# user/bin/python3
# coding:utf-8



from BeautifulReport import BeautifulReport
import unittest,time
import smtplib
from email.mime.text import MIMEText
from email.header import Header
import os
from TestMethod import log
from email.mime.multipart import MIMEMultipart


def NewReport(test_report):
    lists = os.listdir(test_report)
    lists.sort(key=lambda fn: os.path.getatime(test_report + "/" + fn))
    file_new = os.path.join(test_report, lists[-1])
    return file_new


def SendMail(file,STMPServer,From,password,To):
    f = open(file,'rb')
    mailbody = f.read()
    f.close()
    stmpserver = STMPServer
    user = From
    password = password
    subject = '自動化測試報告'
    msgRoot = MIMEMultipart()
    text_msg = MIMEText(mailbody,'html','utf-8')
    msgRoot.attach(text_msg)
    file_msg = MIMEText(mailbody,'base64','utf-8')
    file_msg["Content-Type"] = 'application/octet-stream'
    basename = os.path.basename(file)
    file_msg["Content-Disposition"] = 'attachment; filename=''' + basename + ''
    msgRoot.attach(file_msg)
    msgRoot['Subject'] = Header(subject,'utf-8')
    msgRoot['From'] = From
    msgRoot['To'] = To
    smtp = smtplib.SMTP()
    smtp.connect(stmpserver)
    smtp.login(user, password)
    smtp.sendmail(msgRoot['From'], msgRoot['To'], msgRoot.as_string())
    smtp.quit()

if __name__ == '__main__':
    logprint = log.Log()
    logprint.logOutput()
    test_suite = unittest.defaultTestLoader.discover('../TestCase', pattern='test*.py')
    result = BeautifulReport(test_suite)
    now = time.strftime("%Y%m%d%H%M%S")
    test_dir = '../TestReport/'
    report_dir = '../TestReport/'
    test_report = result.report(filename=now,description='雲智控用例測試報告', report_dir=report_dir, theme='theme_memories')
    report = NewReport(test_dir)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章