Merge pull request #3215 from pytest-dev/bugfix/985/disable-output-capturing-in-doctest

Disable output capturing in doctest
This commit is contained in:
Bruno Oliveira 2018-02-17 18:39:32 -02:00 committed by GitHub
commit 9d879bee36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -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,

1
changelog/985.bugfix Normal file
View File

@ -0,0 +1 @@
Fixed output capture handling in doctests on macOS.

View File

@ -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