HtmlTestRunner icon indicating copy to clipboard operation
HtmlTestRunner copied to clipboard

UnicodeEncodeError

Open vladislavfrolov opened this issue 5 years ago • 4 comments

  • 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.

vladislavfrolov avatar Apr 01 '19 11:04 vladislavfrolov

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)

R-N avatar Mar 09 '20 10:03 R-N

hello guyz, facing the same issue, where can i get the result.py(), i am unable to locate it in my machine

RoshanRajkumar1208 avatar Sep 07 '21 07:09 RoshanRajkumar1208

  • 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()?

RoshanRajkumar1208 avatar Sep 07 '21 07:09 RoshanRajkumar1208

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.

vladislavfrolov avatar Sep 07 '21 08:09 vladislavfrolov