执行用例,并生成报告——discover,HTMLRunner

 HTMLRunner需要下载Python3的格式,懒人链接:http://pan.baidu.com/s/1tp3Ts

参考:http://bbs.chinaunix.net/thread-4154743-1-1.html

下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html

修改后下载地址:http://pan.baidu.com/s/1tp3Ts

修改汇总:

第94行,将import StringIO修改成import io

第539行,将self.outputBuffer = StringIO.StringIO()修改成self.outputBuffer= io.StringIO()

第642行,将if not rmap.has_key(cls):修改成if not cls in rmap:

第766行,将uo = o.decode(‘latin-1‘)修改成uo = e

第766行,将uo = o.decode(‘latin-1‘)修改成uo = e

第775行,将ue = e.decode(‘latin-1‘)修改成ue = e

第631行,将print >> sys.stderr, ‘\nTime Elapsed: %s‘ %(self.stopTime-self.startTime)修改成print(sys.stderr, ‘\nTimeElapsed: %s‘ % (self.stopTime-self.startTime))

 发现还报错自己修改为,发现不报错了。print(sys.stderr, ‘\nTime Elapsed: %s‘ % (self.stopTime-self.startTime)) 

 

 

执行用例并生成报告代码:

import sys,HTMLTestRunner,unittest,time
def filePath(path):
return os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))),path)

def sendEmail(report_path,report_name)
   ...
详情请跳转到:http://www.cnblogs.com/langhuagungun/p/9028566.html
if __name__=="__main__":
  #所有的测试用例都放在testcase文件下,用例文件都已test_xxx.py命名
casepath=filePath('testcase')
disconver=unittest.defaultTestLoader.discover(casepath,pattern='test_*.py',top_level_dir=None)
now=time.strftime('%Y%m%d%H%M',time.localtime(time.time()))
reportname=filePath('report')+'\\'+now+'result.html'
fp=open(reportname,'wb')
runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title=u'接口测试报告',description=u'用例执行情况')
runner.run(disconver)
fp.close()
#调用上文的发送邮件函数
sendEmail(publicApi.reportPath(),reportname)

 

转载于:https://www.cnblogs.com/langhuagungun/p/9028582.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值