Skip to content

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

@lsaffre

Description

@lsaffre

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: doctestsrelated to the doctests builtin plugintype: 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