Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/3583.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix encoding error with `print` statements in doctests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be rst:

Fix encoding error with ``print`` statements in doctests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is RST; reStructuredText uses single backticks for individual identifiers, while double backticks are for arbitrary inline code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you are right, sorry;

We use inline code in the changelog though because there won't be any references to it in the final document (but TBH I don't remember if they render differently).

2 changes: 1 addition & 1 deletion src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class UnicodeSpoof(_SpoofOut):

def getvalue(self):
result = _SpoofOut.getvalue(self)
if encoding:
if encoding and isinstance(result, bytes):
result = result.decode(encoding)
return result

Expand Down
16 changes: 16 additions & 0 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,22 @@ def fix_bad_unicode(text):
result = testdir.runpytest(p, "--doctest-modules")
result.stdout.fnmatch_lines(["* 1 passed *"])

def test_print_unicode_value(self, testdir):
"""
Test case for issue 3583: Printing Unicode in doctest under Python 2.7
doesn't work
"""
p = testdir.maketxtfile(
test_print_unicode_value=r"""
Here is a doctest::

>>> print(u'\xE5\xE9\xEE\xF8\xFC')
åéîøü
"""
)
result = testdir.runpytest(p)
result.stdout.fnmatch_lines(["* 1 passed *"])

def test_reportinfo(self, testdir):
"""
Test case to make sure that DoctestItem.reportinfo() returns lineno.
Expand Down