下載HTMLTestRunner.py 第三方庫 ,參考地址:http://tungwaiyip.info/software/HTMLTestRunner.html
報告顯示中文亂碼問題的解決方式
輸出的報告中可能包含中文,需要確定一下HTMLTestRunner.py源文件的編碼方式
首先確認在引用HTMLTestRunner的代碼文件中設置編碼
- import sys
- reload(sys)
- sys.setdefaultencoding('utf-8')
- # o and e should be byte string because they are collected from stdout and stderr?
- if isinstance(o,str):
- # TODO: some problem with 'string_escape': it escape \n 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 \n and mess up formating
- # ue = unicode(e.encode('string_escape'))
- #ue = e.decode('latin-1')
- else:
- ue = e
- # o and e should be byte string because they are collected from stdout and stderr?
- if isinstance(o,str):
- # TODO: some problem with 'string_escape': it escape \n and mess up formating
- # uo = unicode(o.encode('string_escape'))
- #uo = o.decode('latin-1')
- uo = o.decode('utf-8')
- else:
- uo = o
- if isinstance(e,str):
- # TODO: some problem with 'string_escape': it escape \n and mess up formating
- # ue = unicode(e.encode('string_escape'))
- #ue = e.decode('latin-1')
- ue = e.decode('utf-8')
- else:
- ue = e