File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 1+ Fix encoding error with `print ` statements in doctests
Original file line number Diff line number Diff line change @@ -505,7 +505,7 @@ class UnicodeSpoof(_SpoofOut):
505505
506506 def getvalue (self ):
507507 result = _SpoofOut .getvalue (self )
508- if encoding :
508+ if encoding and isinstance ( result , bytes ) :
509509 result = result .decode (encoding )
510510 return result
511511
Original file line number Diff line number Diff line change @@ -655,6 +655,22 @@ def fix_bad_unicode(text):
655655 result = testdir .runpytest (p , "--doctest-modules" )
656656 result .stdout .fnmatch_lines (["* 1 passed *" ])
657657
658+ def test_print_unicode_value (self , testdir ):
659+ """
660+ Test case for issue 3583: Printing Unicode in doctest under Python 2.7
661+ doesn't work
662+ """
663+ p = testdir .maketxtfile (
664+ test_print_unicode_value = r"""
665+ Here is a doctest::
666+
667+ >>> print(u'\xE5\xE9\xEE\xF8\xFC')
668+ åéîøü
669+ """
670+ )
671+ result = testdir .runpytest (p )
672+ result .stdout .fnmatch_lines (["* 1 passed *" ])
673+
658674 def test_reportinfo (self , testdir ):
659675 """
660676 Test case to make sure that DoctestItem.reportinfo() returns lineno.
You can’t perform that action at this time.
0 commit comments