pytest-dev / pytest-dev/pytest-html

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

Open
#558 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
779
Forks
260
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at pytest_html/plugin.py line 156, where report.nodeid is decoded with unicode_escape, and reproduce the failure using a test parameter containing a Windows path such as C:\Program Files (x86)\New Folder. Check that report generation completes without the UnicodeDecodeError and that the parameter text remains represented correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.