django 生成HTML报告

上一篇 / 下一篇  2020-09-17 15:08:44 / 个人分类:Django

最近自动化测试平台需要用到邮件发送HTML报告功能,下面是生成html报告python代码。
def test(resultid,title,status,remark,createtime,finishTime):

    table_tr0 = ''
    if status == 30:
        numsucc = 1
        numfail = 0
    else:
        numfail = 1
        numsucc = 0
    html = Template_mixin()
   
    table_td = html.TABLE_TMPL % dict(version = resultid,step=title,runresult=remark,createtime = createtime.strftime('%Y-%m-%d %H:%M:%S'),endtime = finishTime.strftime('%Y-%m-%d %H:%M:%S'))
    table_tr0 += table_td
    total_str = '共 %s,通过 %s,失败 %s' % (numfail + numsucc, numsucc, numfail)
    utput = html.HTML_TMPL % dict(value = total_str,table_tr = table_tr0,)
    #print('output',output)
    # 生成html报告
    filename='{date}_TestReport.html'.format(date=time.strftime('%Y%m%d%H%M%S'))
    
    print(filename)
    #获取report的路径
    dir= os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),'report')
    filename=os.path.join(dir,filename)
 
 
    with open(filename, 'wb') as f:
        f.write(output.encode('utf8'))
    
        file = new_report(dir)
        #print(file)
        #send_mail(file)  # 发送测试报告
    return file

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar