Skip to content

Commit d382f3e

Browse files
committed
[#3583] Fix encoding error with print statements in doctests
This fix was suggested by Stack Overflow user phd in <https://stackoverflow.com/a/50863820/744178>.
1 parent 5221a14 commit d382f3e

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

changelog/3583.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix encoding error with `print` statements in doctests

src/_pytest/doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)