HTMLTestRunner测试报告中文乱码问题
HTMLTestRunner测试报告中文乱码问题
问题描述
html-testRunner==1.1.2
Python 3.7.1
调用HtmlTestRunner.HTMLTestRunner输出中文内容时产生乱码
原代码
import HtmlTestRunner
if __ name __ == ‘__main __’:
suite = unittest.TestSuite()
suite.addTest(User_Authentication('test_something2'))
suite.addTest(User_Authentication('test_something1'))
suite.addTest(User_Authentication('test_something3'))
#unittest.main()
runner = HtmlTestRunner.HTMLTestRunner(output='C:/report/',
verbosity=2, report_title="测试报告")
解决方案
修改C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib\site-packages\HtmlTestRunner\result.py:def generate_file(self, output, report_name, report):
with open(path_file, ‘w’) as report_file: —>
with open(path_file, ‘w’, encoding=‘utf-8’) as report_file: