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

Unicode issues with pytest.fail #2258

Closed
AmatanHead opened this issue Feb 16, 2017 · 4 comments
Closed

Unicode issues with pytest.fail #2258

AmatanHead opened this issue Feb 16, 2017 · 4 comments
Labels
topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed

Comments

@AmatanHead
Copy link

Hello!

I'm passing a unicode-encoded string to pytest.fail with non-ascii symbols, e.g. pytest.fail(u'фыв'.encode('utf-8')) and I'm getting an invalid output . Removing .encode('utf-8') restores things back to normal:

_________ test_unicode_non_unicode _________

    def test_unicode_non_unicode():
>       pytest.fail(u'фыв'.encode('utf-8'))
E       Failed: ������

test.py:14: Failed
___________ test_unicode_unicode ___________

    def test_unicode_unicode():
>       pytest.fail(u'фыв')
E       Failed: фыв

test.py:17: Failed

I've also ran into troubles using this with Jenkins CI (v2.41). Whenever I pass u'фыв' without .encode('utf-8'), py.test encodes it using unicode escape codec so I get \u0444\u044b\u0432. If I add export PYTHONIOENCODING=utf-8 before executing py.test, I get (even without .encode('utf-8')).

Reproduced it in mac os and ubuntu 12.04. Python version is 2.7.13, also reproduces with 2.7.3. Py.test version is 3.0.6.
LC_ALL and similar settings all set to en_US.UTF-8 both in Jenkins and in my terminal.

@The-Compiler
Copy link
Member

What if you do the same with print?

@AmatanHead
Copy link
Author

It works fine:

>>> print u'фыв'.encode('utf-8')
фыв
>>> print u'фыв'
фыв

@nicoddemus nicoddemus added topic: reporting related to terminal output and user-facing messages and errors type: bug problem that needs to be addressed labels Sep 28, 2017
@kmantel
Copy link

kmantel commented May 26, 2018

I was able to produce a similar version of this in mac os on python 3.5.3 and pytest 3.6.0

______________________________________________ test_unicode_non_unicode _______________________________________________

    def test_unicode_non_unicode():
\x1b[1m>       pytest.fail(u'\u0444\u044b\u0432'.encode('utf-8'))\x1b[0m
E       Failed: <unprintable Failed object>

tests/test_unicode.py:5: Failed
________________________________________________ test_unicode_unicode _________________________________________________

    def test_unicode_unicode():
\x1b[1m>       pytest.fail(u'\u0444\u044b\u0432')\x1b[0m
\x1b[1m\x1b[31mE       Failed: \u0444\u044b\u0432\x1b[0m

tests/test_unicode.py:9: Failed```

is pytest intended to support messages like this?

@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

6 participants