File tree 3 files changed +18
-1
lines changed
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):
505
505
506
506
def getvalue (self ):
507
507
result = _SpoofOut .getvalue (self )
508
- if encoding :
508
+ if encoding and isinstance ( result , bytes ) :
509
509
result = result .decode (encoding )
510
510
return result
511
511
Original file line number Diff line number Diff line change @@ -655,6 +655,22 @@ def fix_bad_unicode(text):
655
655
result = testdir .runpytest (p , "--doctest-modules" )
656
656
result .stdout .fnmatch_lines (["* 1 passed *" ])
657
657
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
+
658
674
def test_reportinfo (self , testdir ):
659
675
"""
660
676
Test case to make sure that DoctestItem.reportinfo() returns lineno.
You can’t perform that action at this time.
0 commit comments