Skip to content

Commit

Permalink
Merge pull request #3215 from pytest-dev/bugfix/985/disable-output-ca…
Browse files Browse the repository at this point in the history
…pturing-in-doctest

Disable output capturing in doctest
  • Loading branch information
nicoddemus committed Feb 17, 2018
2 parents 0f6879b + 4131d3f commit 9d879be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
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 @@ -298,10 +298,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

0 comments on commit 9d879be

Please sign in to comment.