Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repr locals should show the variable name on failure to encode #5038

Closed
gaborbernat opened this issue Apr 3, 2019 · 3 comments
Closed

repr locals should show the variable name on failure to encode #5038

gaborbernat opened this issue Apr 3, 2019 · 3 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed

Comments

@gaborbernat
Copy link
Contributor

https://github.com/pytest-dev/pytest/blob/master/src/_pytest/_code/code.py#L717

tests/unit/session/test_parallel.py::test_parallel_show_output INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/main.py", line 209, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/main.py", line 249, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 68, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 62, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "<remote exec>", line 67, in pytest_runtestloop
INTERNALERROR>   File "<remote exec>", line 84, in run_one_test
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 68, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 62, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/runner.py", line 78, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/runner.py", line 93, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/runner.py", line 175, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 68, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 62, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/skipping.py", line 127, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/runner.py", line 249, in pytest_runtest_makereport
INTERNALERROR>     return TestReport.from_item_and_call(item, call)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/reports.py", line 361, in from_item_and_call
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/python.py", line 848, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/nodes.py", line 285, in _repr_failure_py
INTERNALERROR>     truncate_locals=truncate_locals,
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 552, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 790, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 747, in repr_traceback
INTERNALERROR>     reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 717, in repr_traceback_entry
INTERNALERROR>     localsrepr = self.repr_locals(entry.locals)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 679, in repr_locals
INTERNALERROR>     str_repr = pprint.pformat(value)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 63, in pformat
INTERNALERROR>     return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 122, in pformat
INTERNALERROR>     self._format(object, sio, 0, 0, {}, 0)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 140, in _format
INTERNALERROR>     rep = self._repr(object, context, level - 1)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 226, in _repr
INTERNALERROR>     self._depth, level)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 238, in format
INTERNALERROR>     return _safe_repr(object, context, maxlevels, level)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 323, in _safe_repr
INTERNALERROR>     rep = repr(object)
INTERNALERROR> UnicodeEncodeError: 'ascii' codec can't encode character u'\u280b' in position 40: ordinal not in range(128)

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/main.py", line 209, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/main.py", line 249, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 68, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 62, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/xdist/dsession.py", line 115, in pytest_runtestloop
INTERNALERROR>     self.loop_once()
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/xdist/dsession.py", line 138, in loop_once
INTERNALERROR>     call(**kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/xdist/dsession.py", line 180, in worker_workerfinished
INTERNALERROR>     assert not crashitem, (crashitem, node)
INTERNALERROR> AssertionError: ('tests/unit/session/test_parallel.py::test_parallel_show_output', <WorkerController gw0>)
INTERNALERROR> assert not 'tests/unit/session/test_parallel.py::test_parallel_show_output'
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/main.py", line 209, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/main.py", line 249, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 68, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 62, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "<remote exec>", line 67, in pytest_runtestloop
INTERNALERROR>   File "<remote exec>", line 84, in run_one_test
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 68, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 62, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/runner.py", line 78, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/runner.py", line 93, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/runner.py", line 175, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/hooks.py", line 289, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 68, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/manager.py", line 62, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/skipping.py", line 127, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 81, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/runner.py", line 249, in pytest_runtest_makereport
INTERNALERROR>     return TestReport.from_item_and_call(item, call)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/reports.py", line 361, in from_item_and_call
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/python.py", line 848, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/nodes.py", line 285, in _repr_failure_py
INTERNALERROR>     truncate_locals=truncate_locals,
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 552, in getrepr
INTERNALERROR>     return fmt.repr_excinfo(self)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 790, in repr_excinfo
INTERNALERROR>     reprtraceback = self.repr_traceback(excinfo)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 747, in repr_traceback
INTERNALERROR>     reprentry = self.repr_traceback_entry(entry, einfo)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 717, in repr_traceback_entry
INTERNALERROR>     localsrepr = self.repr_locals(entry.locals)
INTERNALERROR>   File "/home/vsts/work/1/s/.tox/py27/lib/python2.7/site-packages/_pytest/_code/code.py", line 679, in repr_locals
INTERNALERROR>     str_repr = pprint.pformat(value)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 63, in pformat
INTERNALERROR>     return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 122, in pformat
INTERNALERROR>     self._format(object, sio, 0, 0, {}, 0)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 140, in _format
INTERNALERROR>     rep = self._repr(object, context, level - 1)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 226, in _repr
INTERNALERROR>     self._depth, level)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 238, in format
INTERNALERROR>     return _safe_repr(object, context, maxlevels, level)
INTERNALERROR>   File "/opt/hostedtoolcache/Python/2.7.15/x64/lib/python2.7/pprint.py", line 323, in _safe_repr
INTERNALERROR>     rep = repr(object)
INTERNALERROR> UnicodeEncodeError: 'ascii' codec can't encode character u'\u280b' in position 198: ordinal not in range(128)

This way it's hard to understand where and what is bad 🤔

@blueyed
Copy link
Contributor

blueyed commented Apr 3, 2019

Well, not crashing in the first place would be better.. :)

Do you have a reproducible example?

@blueyed blueyed added topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed labels Apr 3, 2019
@gaborbernat
Copy link
Contributor Author

Sadly did not manage to reproduce locally but is fairly stable on CI - https://dev.azure.com/toxdev/tox/_build/results?buildId=1472

@asottile
Copy link
Member

asottile commented Jun 2, 2020

hello, first off thank you for the issue!

python 2.x support has ended for pytest core.

we've decided in #7296 to close the python-2-specific issues to free up some space in our backlog. however, in accordance to our python 2.7 and 3.4 support community patches will still be accepted to the 4.6 series to fix bugs for python 2. (so if this issue is important to you and you have a patch to fix it, feel free to make a PR targeting the 4.6.x branch despite this ticket being closed).

@asottile asottile closed this as completed Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

4 participants