diff --git a/changelog/3583.bugfix.rst b/changelog/3583.bugfix.rst new file mode 100644 index 000000000..cfa662580 --- /dev/null +++ b/changelog/3583.bugfix.rst @@ -0,0 +1 @@ +Fix encoding error with `print` statements in doctests diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py index 3b58f955f..b0a3ad08d 100644 --- a/src/_pytest/doctest.py +++ b/src/_pytest/doctest.py @@ -505,7 +505,7 @@ def _fix_spoof_python2(runner, encoding): def getvalue(self): result = _SpoofOut.getvalue(self) - if encoding: + if encoding and isinstance(result, bytes): result = result.decode(encoding) return result