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

Failure when traceback includes unicode strings #1864

Closed
dwaynebailey opened this issue Aug 24, 2016 · 2 comments
Closed

Failure when traceback includes unicode strings #1864

dwaynebailey opened this issue Aug 24, 2016 · 2 comments
Labels
type: regression indicates a problem that was introduced in a release which was working previously

Comments

@dwaynebailey
Copy link

When the failed asserts include unicode text then you will get a UnicodeEncodeError on pytest >3.0, this works correctly on 2.9.2.

Using:

def test_unicode_in_error():
    a = u"使用自動捲動 (&A)"
    b = u"使用自動捲動"
    assert a == b

pip install pytest==3.0.1

test_simple.py 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/main.py", line 96, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/main.py", line 131, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/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 "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/main.py", line 152, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/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 "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
INTERNALERROR>     _MultiCall(methods, kwargs, hook.spec_opts).execute()
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/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 "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 253, in _wrapped_call
INTERNALERROR>     return call_outcome.get_result()
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
INTERNALERROR>     _reraise(*ex)  # noqa
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 264, in __init__
INTERNALERROR>     self.result = func()
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/runner.py", line 66, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/runner.py", line 79, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/runner.py", line 133, in call_and_report
INTERNALERROR>     call = call_runtest_hook(item, when, **kwds)
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/runner.py", line 151, in call_runtest_hook
INTERNALERROR>     return CallInfo(lambda: ihook(item=item, **kwds), when=when)
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/runner.py", line 168, in __init__
INTERNALERROR>     self.excinfo = ExceptionInfo()
INTERNALERROR>   File "/Users/dwayne/dev/envs/pytest-unicode/lib/python2.7/site-packages/_pytest/_code/code.py", line 357, in __init__
INTERNALERROR>     exprinfo = str(tup[1])
INTERNALERROR> UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-13: ordinal not in range(128)

pip install pytest==2.9.2

    def test_unicode_in_error():
        a = u"使用自動捲動 (&A)"
        b = u"使用自動捲動"
        assert a != b
>       assert a == b
E       assert '使用自動捲動 (&A)' == '使用自動捲動'
E         - 使用自動捲動 (&A)
E         + 使用自動捲動
@The-Compiler
Copy link
Member

Seems to work correctly with Python 3.

In Python 2, to reproduce the bug, this also needs a # encoding: utf-8 comment.

Bisected to d1852a4 - cc @flub

@nicoddemus nicoddemus added the type: regression indicates a problem that was introduced in a release which was working previously label Aug 24, 2016
@nicoddemus
Copy link
Member

Fixed in #1870.

dwaynebailey added a commit to dwaynebailey/translate that referenced this issue Sep 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
Development

No branches or pull requests

3 participants