參考後總結,方便自己日後翻看
--------------------------------------------------------------------------------
因爲python2 和python3 api部分修改的原因,python3使用HTMLTestRunner.py時需要對應用文件做部分修改
修改如下:
第94行,將import StringIO修改成import io第539行,將self.outputBuffer = StringIO.StringIO()修改成self.outputBuffer = io.StringIO()
第631行,將print >> sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)修改成print(sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime))
第642行,將if not rmap.has_key(cls):修改成if not cls in rmap:
第766行,將uo = o.decode('latin-1')修改成uo = e
第772行,將ue = e.decode('latin-1')修改成ue = e
修改的部分是我根據別人的講解操作的,修改完後再次運行:
出現了這個錯誤:
self.stream.write(output.encode('utf8'))
TypeError: write() argument must be str, not bytes
查了一下才發現文件打開方式有問題,把之前的打開語句修改爲用二進制方式打開就沒有問題
原代碼:
with open('HtmlReport.html', 'w') as f:
修改後:
with open('HtmlReport.html', 'wb') as f:
再次運行: