From 391553887b072d1a533a83226995785bef28fe34 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 13 Feb 2018 12:08:39 -0500 Subject: [PATCH] Disable output capturing in doctest to avoid losing reference to stdout. Fixes #985. --- _pytest/doctest.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/_pytest/doctest.py b/_pytest/doctest.py index bba90e551..112a700ec 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, division, print_function import traceback +import sys import pytest from _pytest._code.code import ExceptionInfo, ReprFileLocation, TerminalRepr @@ -103,8 +104,19 @@ class DoctestItem(pytest.Item): def runtest(self): _check_all_skipped(self.dtest) + self._disable_output_capturing() self.runner.run(self.dtest) + def _disable_output_capturing(self): + """ + Disable output capturing. Otherwise, stdout is lost to doctest (#985) + """ + capman = self.config.pluginmanager.getplugin("capturemanager") + if capman: + out, err = capman.suspend_global_capture(in_=True) + sys.stdout.write(out) + sys.stdout.write(err) + def repr_failure(self, excinfo): import doctest if excinfo.errisinstance((doctest.DocTestFailure,