欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-29 18:06:16
一、导入了HTMLTestRunner模块,报错:No module named StringIO,在python3.x中确实没有,在第94行引入的名称改成import io,539行要改成self.outputBuffer = io.BytesIO(),因为写入磁盘为字节流形式,所以在119行要写 ......

一、导入了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))