Skip to content

Printing Unicode in doctest under Python 2.7 doesn't work #3583

@jwodder

Description

@jwodder

As of pytest 3.6.1, doctests that prints Unicode output (not just evaluating to Unicode; they have to call print) are failing with a UnicodeEncodeError under Python 2.7 but succeeding under Python 3.3+, regardless of locale or whether doctest_encoding = utf-8 is set in pytest.ini. This has been observed on both Mac OS X and Ubuntu Trusty & Xenial.

This bug was first noticed in https://stackoverflow.com/q/50860112/744178; see there for slightly more information. Issue #2728 may also be related.

Minimal example:

pytest-bug.rst:

Here is a failing example::

    >>> print(u'\xE5\xE9\xEE\xF8\xFC')
    åéîøü

Running pytest pyttest-bug.rst fails under Python 2.7.10 and succeeds under Python 3.6.5.

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