1.使用unittest自动化测试框架,使用HTMLTestRunner生成测试报告,中文乱码问题!
如图
2.解决方法:
第一步:先在自己的测试脚本中添加
import sys reload(sys) sys.setdefaultencoding('utf-8')
第二步,查找 HTMLTestRunner中的这段代码,把将其中的编码“latin-1”修改为“utf-8”后保存
if isinstance(o,str): # TODO: some problem with 'string_escape': it escape and mess up formating # uo = unicode(o.encode('string_escape')) #uo = o.decode('latin-1') else: uo = o if isinstance(e,str): # TODO: some problem with 'string_escape': it escape and mess up formating # ue = unicode(e.encode('string_escape')) #ue = e.decode('latin-1') else: ue = e
如下,然后重新运行一下就可以解决了!
if isinstance(o,str): # TODO: some problem with 'string_escape': it escape and mess up formating # uo = unicode(o.encode('string_escape')) uo = o.decode('utf-8') else: uo = o if isinstance(e,str): # TODO: some problem with 'string_escape': it escape and mess up formating # ue = unicode(e.encode('string_escape')) uo = o.decode('utf-8') else: ue = e