Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions _pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -103,8 +105,21 @@ def setup(self):

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,
Expand Down
1 change: 1 addition & 0 deletions changelog/985.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed output capture handling in doctests on macOS.
4 changes: 0 additions & 4 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,6 @@ def test_2():
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
Expand Down