Skip to content

Commit 9d879be

Browse files
authored
Merge pull request #3215 from pytest-dev/bugfix/985/disable-output-capturing-in-doctest
Disable output capturing in doctest
2 parents 0f6879b + 4131d3f commit 9d879be

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

_pytest/doctest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from __future__ import absolute_import, division, print_function
33

44
import traceback
5+
import sys
6+
import platform
57

68
import pytest
79
from _pytest._code.code import ExceptionInfo, ReprFileLocation, TerminalRepr
@@ -103,8 +105,21 @@ def setup(self):
103105

104106
def runtest(self):
105107
_check_all_skipped(self.dtest)
108+
self._disable_output_capturing_for_darwin()
106109
self.runner.run(self.dtest)
107110

111+
def _disable_output_capturing_for_darwin(self):
112+
"""
113+
Disable output capturing. Otherwise, stdout is lost to doctest (#985)
114+
"""
115+
if platform.system() != 'Darwin':
116+
return
117+
capman = self.config.pluginmanager.getplugin("capturemanager")
118+
if capman:
119+
out, err = capman.suspend_global_capture(in_=True)
120+
sys.stdout.write(out)
121+
sys.stderr.write(err)
122+
108123
def repr_failure(self, excinfo):
109124
import doctest
110125
if excinfo.errisinstance((doctest.DocTestFailure,

changelog/985.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed output capture handling in doctests on macOS.

testing/test_pdb.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,6 @@ def test_2():
298298
child.read()
299299
self.flush(child)
300300

301-
# For some reason the interaction between doctest's and pytest's output
302-
# capturing mechanisms are messing up the stdout on mac. (See #985).
303-
# Should be solvable, but skipping until we have a chance to investigate.
304-
@pytest.mark.xfail("sys.platform == 'darwin'", reason='See issue #985', run=False)
305301
def test_pdb_interaction_doctest(self, testdir):
306302
p1 = testdir.makepyfile("""
307303
import pytest

0 commit comments

Comments
 (0)