HtmlTestRunner
HtmlTestRunner copied to clipboard
UnicodeEncodeError
- HtmlTestRunner version: 1.2
- Python version: 3.7.0
- Operating System: Windows 10
Description
I was trying to get report generated and saved in my local folder, but I got this error
Traceback (most recent call last):
File "test_suite_runner.py", line 24, in <module>
runner.run(all_tests_suite)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\HtmlTestRunner\runner.py", line 112, in run
result.generate_reports(self)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\HtmlTestRunner\result.py", line 367, in generate_reports
self.generate_file(testRunner, report_name_body, html_file)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\HtmlTestRunner\result.py", line 404, in generate_file
report_file.write(report)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\encodings\cp1251.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u20bd' in position 3929: character maps to <undefined>
What I Did
What helped me get rid of this error was adding encoding='utf-8' in generate_file() in result.py on line 403
with open(path_file, 'w', encoding='utf-8') as report_file:
report_file.write(report)
I'm very new to programming so I don't know if you need to do something with this or this is my local problem.
Hello, I'm experiencing this too. I have added encoding utf-8 option too, but it doesn't work. The characters were \x84 and \x99. Thanks
Edit: Didn't know I had to do it on the source code of HtmlTestRunner. The one I added encoding option to was the stream argument (which seems to be not what I expected)
hello guyz, facing the same issue, where can i get the result.py(), i am unable to locate it in my machine
- HtmlTestRunner version: 1.2
- Python version: 3.7.0
- Operating System: Windows 10
Description
I was trying to get report generated and saved in my local folder, but I got this error
Traceback (most recent call last): File "test_suite_runner.py", line 24, in <module> runner.run(all_tests_suite) File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\HtmlTestRunner\runner.py", line 112, in run result.generate_reports(self) File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\HtmlTestRunner\result.py", line 367, in generate_reports self.generate_file(testRunner, report_name_body, html_file) File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\site-packages\HtmlTestRunner\result.py", line 404, in generate_file report_file.write(report) File "C:\Users\admin\AppData\Local\Programs\Python\Python37\lib\encodings\cp1251.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u20bd' in position 3929: character maps to <undefined>
What I Did
What helped me get rid of this error was adding encoding='utf-8' in generate_file() in result.py on line 403
with open(path_file, 'w', encoding='utf-8') as report_file: report_file.write(report)
I'm very new to programming so I don't know if you need to do something with this or this is my local problem.
where do you find the result.py()?
where do you find the result.py()?
@RoshanRajkumar1208 It's in HtmlTestRunner package (https://github.com/oldani/HtmlTestRunner/blob/master/HtmlTestRunner/result.py). Try to look at C:\Python39\Lib\site-packages or something like it, depends on how you installed Python and wich OS you use.