pytest-html icon indicating copy to clipboard operation
pytest-html copied to clipboard

Report fails to escape '\N' and '\U' characters in test parameter

Open elubs opened this issue 3 years ago • 1 comments

running tests including non-escaped characters in parameter value causing plugin to throw the following exception "UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 167-168: malformed \N character escape"

create a test with parameter including non-escaped param for example 'C:\Program Files (x86)\New Folder', results the exception below:

raceback (most recent call last):
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\Scripts\pytest.exe\__main__.py", line 7, in <module>
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\_pytest\config\__init__.py", line 187, in console_main
    code = main()
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\_pytest\config\__init__.py", line 164, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\_pytest\main.py", line 315, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\_pytest\main.py", line 303, in wrap_session
    config.hook.pytest_sessionfinish(
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\_pytest\terminal.py", line 798, in pytest_sessionfinish
    outcome.get_result()
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pytest_html\plugin.py", line 717, in pytest_sessionfinish
    self._post_process_reports()
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pytest_html\plugin.py", line 696, in _post_process_reports
    self.append_passed(test_report)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pytest_html\plugin.py", line 412, in append_passed
    self._appendrow("Passed", report)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pytest_html\plugin.py", line 393, in _appendrow
    result = self.TestResult(outcome, report, self.logfile, self.config)
  File "C:\Users\eyal.lubelski\AppData\Local\Programs\Python\Python310\lib\site-packages\pytest_html\plugin.py", line 156, in __init__
    self.test_id = report.nodeid.encode("utf-8").decode("unicode_escape")
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 167-168: malformed \N character escape

elubs avatar Oct 26 '22 06:10 elubs

Mind testing if this is still an issue in 4.0.0rc0?

BeyondEvil avatar Mar 05 '23 16:03 BeyondEvil