执行用例,并生成报告——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)

猜你喜欢

转载自www.cnblogs.com/langhuagungun/p/9028582.html