diff --git a/_pytest/doctest.py b/_pytest/doctest.py index bba90e551..f54f833ec 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -2,6 +2,8 @@ from __future__ import absolute_import, division, print_function import traceback +import sys +import platform import pytest from _pytest._code.code import ExceptionInfo, ReprFileLocation, TerminalRepr @@ -103,8 +105,21 @@ class DoctestItem(pytest.Item): def runtest(self): _check_all_skipped(self.dtest) + self._disable_output_capturing_for_darwin() self.runner.run(self.dtest) + def _disable_output_capturing_for_darwin(self): + """ + Disable output capturing. Otherwise, stdout is lost to doctest (#985) + """ + if platform.system() != 'Darwin': + return + capman = self.config.pluginmanager.getplugin("capturemanager") + if capman: + out, err = capman.suspend_global_capture(in_=True) + sys.stdout.write(out) + sys.stderr.write(err) + def repr_failure(self, excinfo): import doctest if excinfo.errisinstance((doctest.DocTestFailure, diff --git a/changelog/985.bugfix b/changelog/985.bugfix new file mode 100644 index 000000000..0024b9aa2 --- /dev/null +++ b/changelog/985.bugfix @@ -0,0 +1 @@ +Fixed output capture handling in doctests on macOS. diff --git a/testing/test_pdb.py b/testing/test_pdb.py index d882c2cf6..01604b633 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -298,10 +298,6 @@ class TestPDB(object): child.read() self.flush(child) - # For some reason the interaction between doctest's and pytest's output - # capturing mechanisms are messing up the stdout on mac. (See #985). - # Should be solvable, but skipping until we have a chance to investigate. - @pytest.mark.xfail("sys.platform == 'darwin'", reason='See issue #985', run=False) def test_pdb_interaction_doctest(self, testdir): p1 = testdir.makepyfile(""" import pytest