# encoding: utf-8 """ @author: lileilei @file: py_Html.py @time: 2017/6/5 17:04 """ titles = '接口测试' def title(titles): title = ''' %s ''' % (titles) return title connent = '''

接口测试的结果

''' def shouye(starttime, endtime, passge, fail, excepthions, weizhicuowu): beijing = '''
开始时间: %s
结束时间: %s
耗时: %s
结果: Pass: %s Fail: %s exception: %s weizhicuowu : %s
''' % (starttime, endtime, (endtime - starttime), passge, fail, excepthions, weizhicuowu) return beijing shanghai = '''
''' def passfail(tend): if tend == 'pass': htl = '''''' elif tend == 'fail': htl = '''''' elif tend == 'weizhi': htl = '''''' else: htl = '' return htl def ceshixiangqing(reslt, id, name, key, coneent, url, meth, yuqi, json, relust): xiangqing = ''' %s ''' % (reslt, id, name, key, coneent, url, meth, yuqi, json, passfail(relust)) return xiangqing weibu = '''
用例ID  用例名字 key 请求内容 url 请求方式 预期 实际返回 结果
passfailerrorexect
%s %s %s %s %s %s %s %s
''' def relust(titles, starttime, endtime, passge, fail, id, name, key, coneent, url, meth, yuqi, json, relust, exceptions, weizhi): if type(name) == list: relus = ' ' for i in range(len(name)): if relust[i] == "pass": clazz = "success" elif relust[i] == "fail": clazz = "warning" elif relust[i] == "weizhi": clazz = "danger" else: clazz = 'error' relus += ( ceshixiangqing(clazz, id[i], name[i], key[i], coneent[i], url[i], meth[i], yuqi[i], json[i], relust[i])) text = title(titles) + connent + shouye(starttime, endtime, passge, fail, exceptions, weizhi) + shanghai + relus + weibu else: text = title(titles) + connent + shouye(starttime, endtime, passge, fail, exceptions, weizhi) + shanghai + ceshixiangqing(id, name, key, coneent, url, meth, yuqi, json, relust) + weibu return text def createHtml(filepath, titles, starttime, endtime, passge, fail, id, name, key, coneent, url, meth, yuqi, json, relusts, exceptions, weizhi): texts = relust(titles, starttime, endtime, passge, fail, id, name, key, coneent, url, meth, yuqi, json, relusts, exceptions, weizhi) with open(filepath, 'wb') as f: f.write(texts.encode('utf-8'))