Skip to content

"UnicodeEncodeError: 'ascii' codec can't encode character" in OutcomeException with Python 2 #1178

Closed
@blueyed

Description

@blueyed

When using a unicode string in Python 2 with pytest.fail, there is an internal error.

This happens with jedi-vim's tests, when adding a u in front of the string passed to pytest.fail (https://github.com/wilywampa/jedi-vim/blob/37b47b6fa6d245eae66aeb53a55257b7e3a99808/conftest.py#L22-L25).

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/main.py", line 90, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/main.py", line 121, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/main.py", line 146, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/runner.py", line 65, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/runner.py", line 75, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/runner.py", line 121, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 595, in execute
INTERNALERROR>     return _wrapped_call(hook_impl.function(*args), self.execute)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 249, in _wrapped_call
INTERNALERROR>     wrap_controller.send(call_outcome)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/skipping.py", line 170, in pytest_runtest_makereport
INTERNALERROR>     rep = outcome.get_result()
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/runner.py", line 224, in pytest_runtest_makereport
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/python.py", line 732, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/python.py", line 723, in _repr_failure_py
INTERNALERROR>     return str(excinfo.value)
INTERNALERROR>   File "…/pyenv/2.7.10/envs/jedi-vim2/lib/python2.7/site-packages/_pytest/runner.py", line 433, in __repr__
INTERNALERROR>     return str(self.msg)
INTERNALERROR> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 2069: ordinal not in range(128)

pytest 2.8.2

Metadata

Metadata

Assignees

Labels

type: bugproblem that needs to be addressed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions