class Template_mixin(object):
"""html报告"""
HTML_TMPL = """
自动化测试报告自动化测试报告
测试结果 : %(value)s
body { font-family: Microsoft YaHei,Tahoma,arial,helvetica,sans-serif;padding: 20px;}
步数 | 时间 | 用例执行结果 | 原因 |
---|
%(table_tr)s
"""
TABLE_TMPL = """
%(step)s%(runtime)s%(runresult)s%(reason)s"""if __name__ == ‘__main__‘:
table_tr0 = ‘‘
numfail = 1
numsucc = 9
html = Template_mixin()
table_td = html.TABLE_TMPL % dict(
step=‘1‘,
runtime=datetime.datetime.now(),
runresult=‘Fail‘,
reason=‘失败或成功原因‘,
)
table_tr0 += table_td
total_str = ‘共 %s,通过 %s,失败 %s‘ % (numfail + numsucc, numsucc, numfail)
output = html.HTML_TMPL % dict(
value = total_str,
table_tr = table_tr0,
)
#生成html报告
with open("Decision_KKD.html",‘wb‘) as f:
f.write(output.encode(‘utf-8‘))