oldani / HtmlTestRunner

A Test Runner in python, for Human Readable HTML Reports
MIT License
295 stars 171 forks source link

The runner will report error if the testcase output include chinese random code #66

Open zmayw opened 4 years ago

zmayw commented 4 years ago

Description

I use the HtmlTESTRunner, it reports the follow error. Becouse of my testcase is output the conent like "[{'Text': 'æ\x96°å\x91\x98å·¥å\x85¥è\x81\x8c', ...}]" so I modify the code of HTMLTESTRunner/result.py in 404, as "with open(path_file, 'w', encoding='utf-8') as report_file:", its running is ok! Is this line code need to modify? Traceback (most recent call last): File "D:/autotest/testProject/testcase/suite/suite_test01.py", line 26, in runner.run(suite) File "C:\Program Files (x86)\Python38-32\lib\site-packages\HtmlTestRunner\runner.py", line 112, in run result.generate_reports(self) File "C:\Program Files (x86)\Python38-32\lib\site-packages\HtmlTestRunner\result.py", line 367, in generate_reports self.generate_file(testRunner, report_name_body, html_file) File "C:\Program Files (x86)\Python38-32\lib\site-packages\HtmlTestRunner\result.py", line 404, in generate_file report_file.write(report) UnicodeEncodeError: 'gbk' codec can't encode character '\xe6' in position 9767: illegal multibyte sequence

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
mapleflow commented 4 years ago

windows chinese read/write default gbk,unix always custom utf8. when read/write encoding is best practice