def _fix_spoof_python2(runner, encoding):
from _pytest.compat import _PY2<EOL>if not _PY2:<EOL><INDENT>return<EOL><DEDENT>from doctest import _SpoofOut<EOL>class UnicodeSpoof(_SpoofOut):<EOL><INDENT>def getvalue(self):<EOL><INDENT>result = _SpoofOut.getvalue(self)<EOL>if encoding and isinstance(result, bytes):<EOL><INDENT>result = result.decode(encoding)<EOL><DEDENT>return result<EOL><DEDENT><DEDENT>runner._fakeout = UnicodeSpoof()<EOL>
Installs a "SpoofOut" into the given DebugRunner so it properly deals with unicode output. This
should patch only doctests for text files because they don't have a way to declare their
encoding. Doctests in docstrings from Python modules don't have the same problem given that
Python already decoded the strings.

This fixes the problem related in issue #2434.