计划做一个html页面
py3.4
代码:
测试结果 : %(value)s# -*- coding=utf-8 -*-
#
import time,osclass Template_mixin(object):"""html报告"""HTML_TMPL = r"""自动化测试报告
"""TABLE_TMPL = """ %(table_tr)s版本 操作步骤 用例执行结果 操作时间 """if __name__ == '__main__':table_tr0 = ''numfail = 1numsucc = 9html = Template_mixin()table_td = html.TABLE_TMPL % dict(version = '3.8.8',step='输入正确的用户名,密码进行登录',runresult='登录成功',runtime = time.strftime('%Y-%m-%d %H:%M:%S'),)table_tr0 += table_tdtotal_str = '共 %s,通过 %s,失败 %s' % (numfail + numsucc, numsucc, numfail)output = 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:%(version)s %(step)s %(runresult)s %(runtime)s
#f.write(output)f.write(output.encode('utf8'))
刚开始执行时,会报错
加了f.write(output.encode('utf8')),后可以执行。