Python+unittest+HTMLTestRunner进行接口自动化,以html格式展示结果报告

 

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

HTMLTestRunner.py放置当前的项目文件夹下。

下载的HTMLTestRunner.py是针对python2写的,所以针对python3需要适当更改其内容:

   1.

  问题一:No module named StringIO

  原因:python 3 中 没有 StringIO 这个模块。这里我们需要使用io 这个模块来代替。

  解决方法:

    第94行引入的名称要改,从 import StringIO 改成import io。

    相应的,539行 self.outputBuffer = StringIO.StringIO() 要改成self.outputBuffer = io.BytesIO()

  2.

  问题二:AttributeError: 'dict' object has no attribute 'has_key'

  原因:python 3 字典类型的object 已经不支持 has_key函数,我们需要使用in 来进行遍历。

  解决方法:

    定位到642行,if not rmap.has_key(cls): 需要换成 if not cls in rmap:

  3.

  问题三:'str' object has no attribute 'decode'

  原因:python3 里面对字符的操作中,decode已经拿掉了。

  解决方法:

    定位到772行,把 ue = e.decode('latin-1') 直接改成 ue = e 。

    另外766还有类似的uo = o.decode('latin-1'),改成 uo=o ;

  4.

  问题四 TypeError: can't concat bytes to str

  原因:定位一下,报在了778行的内容escape(uo+ue) 。这是因为我们上面给uo赋值的时候,走的是else流程,uo被赋值的是bytes类型的值。 而bytes类型不能直接转化为 str  类  型。所以我们需要在前面给uo赋值的时候先将bytes类型转换为 str类型。

  解决方法:

    修改768行的 uo = o ,直接改成 uo = o.decode('utf-8') 。

    另外 774还有类似的  ue = e, 改成 ue = e.decode('utf-8')。

  5.

  问题五:TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and 'RPCProxy'

  原因: python3  不支持 print >> sys.stderr 这种写法,这里定义输出流的话,采用print("This is print str",file=sys.stderr) 这种方式。

  解决方法:

    定位到631行,把print的语句修改掉,原来是print >>sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime), 可改成 print('\nTime Elapsed: %s' %        (self.stopTime-self.startTime),file=sys.stderr)

 

  6.问题六:TypeError: 'str' does not support the buffer interface

  原因:定位一下,问题出在118行,这里s是str类型,我们需要把传过来的s转化为bytes类型。

  解决方法:

    定位到118行,把 self.fp.write(s) 修改为 self.fp.write(bytes(s,'UTF-8')) 即可。

  7.问题七:打开生成的html格式的测试报告时中文显示乱码

     解决方法:   

    定位第686行

    self.stream.write(output.encode('UTF-16'))改为:self.stream.write(output)

    同时,运行测试用例的runner代码这样写:

       

    

    或者防止乱码还可以这样做:

      686行self.stream.write(output.encode('UTF-16'))改为:self.stream.write(output.encode('UTF-8'))

    打开HTML文件时 with open(filename,’wb’) as fb:

某大神总结的jmeter深入使用教程:  http://www.cnblogs.com/blongfree/tag/JMeter/default.html?page=3

 

 

  

猜你喜欢

转载自www.cnblogs.com/YUxingxing1/p/9701065.html
今日推荐