基于python语言的自动化测试中生成html的测试报告时HtmlTestRunner模块常见问题

一、导入了HTMLTestRunner模块,报错:No module named StringIO,在python3.x中确实没有,在第94行引入的名称改成import io,539行要改成self.outputBuffer = io.BytesIO(),因为写入磁盘为字节流形式,所以在119行要写城self.fp.write(s.encode()),生成报告时,bytes转化成str。

二、报错:AttributeError:‘dict’ object no attribute ‘has_key’,发现has_key的又被k掉了,所以到642行将if not rmap.has_key(cls)改成if not cls in rmap


三、报错:'str'object has no attribute 'decode',貌似是3里面对字符的操作,decode已经拿掉了。定位一下,772行 ue=e.decode('latin-1'),直接改成ue=e,另外766还有类似的uo = o.decode('latin-1')可不动先留着

四、报错:TypeError:can't concat bytes to str,bytes和str不能直接连起来,那么在778行escape(uo+ue),修改成escape(str(uo)+ue)

五、报错:pring >>sys.syderr, '\nTime Elapsed: %s' % (selfl.stopTime-self.startTime)
TpyeError: unsupported operand type(s) for >>:'buildtin_function_or_method' and 'RPCProxy' 相信这条很多刚接触3.x的人都明白,2和3是很不同,那么在3中print后面是不会跟>>这样的,所以在631行,把print的语句修改掉,原来是pring >>sys.syderr, '\nTime Elapsed: %s' % (selfl.stopTime-self.startTime),可改成prin(sys.syderr, '\nTime Elapsed: %s' % (selfl.stopTime-self.startTime))

猜你喜欢

转载自www.cnblogs.com/vevian/p/11072305.html