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

pytest fails with UnicodeEncodeError on doctest containing "print(u'Ä')" #2728

Closed
lsaffre opened this issue Aug 29, 2017 · 5 comments
Closed
Labels
plugin: doctests related to the doctests builtin plugin type: bug problem that needs to be addressed

Comments

@lsaffre
Copy link

lsaffre commented Aug 29, 2017

I am stuck... please help to find a workaround!
In an otherwise empty directory I have a file named "test.txt" with two lines of text:

>>> print(u'Ä')
Ä

I verified whether my file is indeed UTF-8 encoded:

$ file test.txt
test.txt: UTF-8 Unicode text

When I run pytest on this, it fails with a UnicodeEncodeError.
Here is a full session log: https://bpaste.net/show/b0adfb13e3e3

When I remove the "u" (i.e. the output of the command being tested is itself encoded), then pytest works well and says that the test passed. The problem occurs only under Python 2 and only when I want to test unicode output which contains non-ascii text.

Reproduced on several machines with
pytest version 3.2.1 and 3.2.2.dev17+g539523c (current clone)
Python 2.7.9 and 2.7.12

Thanks for any suggesteions.
Luc

@RonnyPfannschmidt
Copy link
Member

this looks like even more of a problem - pytest is already working around some of the rotten unicode related bugs in doctest

@nicoddemus @hpk42 im starting to think we should move doctest in a extra plugin that can have bugfixes independent of pytest

@nicoddemus
Copy link
Member

@lsaffre thanks for the report. I managed to reproduce and workaround the problem by changing the input text to:

>>> print('Ä')  # doctest: +ALLOW_UNICODE
Ä
============================= test session starts =============================
platform win32 -- Python 2.7.13, pytest-3.2.2.dev8+g16b248f.d20170817, py-1.4.34, pluggy-0.4.0
rootdir: C:\pytest\.tmp, inifile: pytest.ini
plugins: ast-back-to-python-0.1.0, hypothesis-3.13.1
collected 1 item

.tmp\test.txt .

========================== 1 passed in 0.01 seconds ===========================

But this still feels like a bug that should be investigated.

im starting to think we should move doctest in a extra plugin that can have bugfixes independent of pytest

Not sure having doctest as a separate plugin from pytest would bring much benefit, we have been having fairly regular bug-fix releases lately.

@nicoddemus nicoddemus added plugin: doctests related to the doctests builtin plugin type: bug problem that needs to be addressed labels Aug 29, 2017
@lsaffre
Copy link
Author

lsaffre commented Aug 30, 2017 via email

@nicoddemus
Copy link
Member

@lsaffre hmm that's strange. Which OS are you using?

@asottile
Copy link
Member

asottile commented Jul 9, 2018

🎉 this got fixed with #3584 -- upgrade to pytest>=3.6.2

@asottile asottile closed this as completed Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: doctests related to the doctests builtin plugin type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

4 participants