remove dupped_stdout logic and related changes, also simplify pytest_runtest_* calls to not use a contextlib with-decorator anymore.

This commit is contained in:
holger krekel 2014-04-01 15:03:17 +02:00
parent ce8678e6d5
commit 3b8935c533
7 changed files with 23 additions and 36 deletions

View File

@ -26,6 +26,10 @@ NEXT (2.6)
- fix issue412: messing with stdout/stderr FD-level streams is now
captured without crashes.
- simplified internal capturing mechanism and made it more robust
against tests or setups changing FD1/FD2, also better integrated
now with pytest.pdb() in single tests.
2.5.2
-----------------------------------

View File

@ -7,7 +7,6 @@ from __future__ import with_statement
import sys
import os
from tempfile import TemporaryFile
import contextlib
import py
import pytest
@ -34,13 +33,9 @@ def pytest_addoption(parser):
def pytest_load_initial_conftests(early_config, parser, args, __multicall__):
ns = parser.parse_known_args(args)
pluginmanager = early_config.pluginmanager
method = ns.capture
if method != "no":
dupped_stdout = safe_text_dupfile(sys.stdout, "wb")
pluginmanager.register(dupped_stdout, "dupped_stdout")
#pluginmanager.add_shutdown(dupped_stdout.close)
capman = CaptureManager(method)
if ns.capture == "no":
return
capman = CaptureManager(ns.capture)
pluginmanager.register(capman, "capturemanager")
# make sure that capturemanager is properly reset at final shutdown
@ -129,20 +124,23 @@ class CaptureManager:
@pytest.mark.hookwrapper
def pytest_runtest_setup(self, item):
with self.item_capture_wrapper(item, "setup"):
yield
self.resumecapture()
yield
self.suspendcapture_item(item, "setup")
@pytest.mark.hookwrapper
def pytest_runtest_call(self, item):
with self.item_capture_wrapper(item, "call"):
self.activate_funcargs(item)
yield
#self.deactivate_funcargs() called from ctx's suspendcapture()
self.resumecapture()
self.activate_funcargs(item)
yield
#self.deactivate_funcargs() called from suspendcapture()
self.suspendcapture_item(item, "call")
@pytest.mark.hookwrapper
def pytest_runtest_teardown(self, item):
with self.item_capture_wrapper(item, "teardown"):
yield
self.resumecapture()
yield
self.suspendcapture_item(item, "teardown")
@pytest.mark.tryfirst
def pytest_keyboard_interrupt(self, excinfo):
@ -152,10 +150,7 @@ class CaptureManager:
def pytest_internalerror(self, excinfo):
self.reset_capturings()
@contextlib.contextmanager
def item_capture_wrapper(self, item, when):
self.resumecapture()
yield
def suspendcapture_item(self, item, when):
out, err = self.suspendcapture()
item.add_report_section(when, "out", out)
item.add_report_section(when, "err", err)

View File

@ -60,7 +60,6 @@ def pytest_addoption(parser):
def pytest_cmdline_main(config):
genscript = config.getvalue("genscript")
if genscript:
#tw = config.get_terminal_writer()
tw = py.io.TerminalWriter()
deps = ['py', '_pytest', 'pytest']
if sys.version_info < (2,7):

View File

@ -47,8 +47,6 @@ def pytest_unconfigure(config):
def pytest_cmdline_main(config):
if config.option.version:
capman = config.pluginmanager.getplugin("capturemanager")
capman.reset_capturings()
p = py.path.local(pytest.__file__)
sys.stderr.write("This is pytest version %s, imported from %s\n" %
(pytest.__version__, p))
@ -64,7 +62,7 @@ def pytest_cmdline_main(config):
return 0
def showhelp(config):
tw = config.get_terminal_writer()
tw = py.io.TerminalWriter()
tw.write(config._parser.optparser.format_help())
tw.line()
tw.line()

View File

@ -40,7 +40,7 @@ def pytest_addoption(parser):
def pytest_cmdline_main(config):
if config.option.markers:
config.do_configure()
tw = config.get_terminal_writer()
tw = py.io.TerminalWriter()
for line in config.getini("markers"):
name, rest = line.split(":", 1)
tw.write("@pytest.mark.%s:" % name, bold=True)

View File

@ -885,7 +885,7 @@ def _showfixtures_main(config, session):
nodeid = "::".join(map(str, [curdir.bestrelpath(part[0])] + part[1:]))
nodeid.replace(session.fspath.sep, "/")
tw = config.get_terminal_writer()
tw = py.io.TerminalWriter()
verbose = config.getvalue("verbose")
fm = session._fixturemanager

View File

@ -36,10 +36,7 @@ def pytest_addoption(parser):
def pytest_configure(config):
config.option.verbose -= config.option.quiet
out = config.pluginmanager.getplugin("dupped_stdout")
#if out is None:
# out = sys.stdout
reporter = TerminalReporter(config, out)
reporter = TerminalReporter(config, sys.stdout)
config.pluginmanager.register(reporter, 'terminalreporter')
if config.option.debug or config.option.traceconfig:
def mywriter(tags, args):
@ -47,11 +44,6 @@ def pytest_configure(config):
reporter.write_line("[traceconfig] " + msg)
config.trace.root.setprocessor("pytest:config", mywriter)
def get_terminal_writer(config):
tr = config.pluginmanager.getplugin("terminalreporter")
return tr._tw
def getreportopt(config):
reportopts = ""
optvalue = config.option.report
@ -104,7 +96,6 @@ class TerminalReporter:
self.startdir = self.curdir = py.path.local()
if file is None:
file = py.std.sys.stdout
#assert file.encoding
self._tw = self.writer = py.io.TerminalWriter(file)
if self.config.option.color == 'yes':
self._tw.hasmarkup = True