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:
parent
ce8678e6d5
commit
3b8935c533
|
@ -26,6 +26,10 @@ NEXT (2.6)
|
||||||
- fix issue412: messing with stdout/stderr FD-level streams is now
|
- fix issue412: messing with stdout/stderr FD-level streams is now
|
||||||
captured without crashes.
|
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
|
2.5.2
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
|
@ -7,7 +7,6 @@ from __future__ import with_statement
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
import contextlib
|
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -34,13 +33,9 @@ def pytest_addoption(parser):
|
||||||
def pytest_load_initial_conftests(early_config, parser, args, __multicall__):
|
def pytest_load_initial_conftests(early_config, parser, args, __multicall__):
|
||||||
ns = parser.parse_known_args(args)
|
ns = parser.parse_known_args(args)
|
||||||
pluginmanager = early_config.pluginmanager
|
pluginmanager = early_config.pluginmanager
|
||||||
method = ns.capture
|
if ns.capture == "no":
|
||||||
if method != "no":
|
return
|
||||||
dupped_stdout = safe_text_dupfile(sys.stdout, "wb")
|
capman = CaptureManager(ns.capture)
|
||||||
pluginmanager.register(dupped_stdout, "dupped_stdout")
|
|
||||||
#pluginmanager.add_shutdown(dupped_stdout.close)
|
|
||||||
|
|
||||||
capman = CaptureManager(method)
|
|
||||||
pluginmanager.register(capman, "capturemanager")
|
pluginmanager.register(capman, "capturemanager")
|
||||||
|
|
||||||
# make sure that capturemanager is properly reset at final shutdown
|
# make sure that capturemanager is properly reset at final shutdown
|
||||||
|
@ -129,20 +124,23 @@ class CaptureManager:
|
||||||
|
|
||||||
@pytest.mark.hookwrapper
|
@pytest.mark.hookwrapper
|
||||||
def pytest_runtest_setup(self, item):
|
def pytest_runtest_setup(self, item):
|
||||||
with self.item_capture_wrapper(item, "setup"):
|
self.resumecapture()
|
||||||
yield
|
yield
|
||||||
|
self.suspendcapture_item(item, "setup")
|
||||||
|
|
||||||
@pytest.mark.hookwrapper
|
@pytest.mark.hookwrapper
|
||||||
def pytest_runtest_call(self, item):
|
def pytest_runtest_call(self, item):
|
||||||
with self.item_capture_wrapper(item, "call"):
|
self.resumecapture()
|
||||||
self.activate_funcargs(item)
|
self.activate_funcargs(item)
|
||||||
yield
|
yield
|
||||||
#self.deactivate_funcargs() called from ctx's suspendcapture()
|
#self.deactivate_funcargs() called from suspendcapture()
|
||||||
|
self.suspendcapture_item(item, "call")
|
||||||
|
|
||||||
@pytest.mark.hookwrapper
|
@pytest.mark.hookwrapper
|
||||||
def pytest_runtest_teardown(self, item):
|
def pytest_runtest_teardown(self, item):
|
||||||
with self.item_capture_wrapper(item, "teardown"):
|
self.resumecapture()
|
||||||
yield
|
yield
|
||||||
|
self.suspendcapture_item(item, "teardown")
|
||||||
|
|
||||||
@pytest.mark.tryfirst
|
@pytest.mark.tryfirst
|
||||||
def pytest_keyboard_interrupt(self, excinfo):
|
def pytest_keyboard_interrupt(self, excinfo):
|
||||||
|
@ -152,10 +150,7 @@ class CaptureManager:
|
||||||
def pytest_internalerror(self, excinfo):
|
def pytest_internalerror(self, excinfo):
|
||||||
self.reset_capturings()
|
self.reset_capturings()
|
||||||
|
|
||||||
@contextlib.contextmanager
|
def suspendcapture_item(self, item, when):
|
||||||
def item_capture_wrapper(self, item, when):
|
|
||||||
self.resumecapture()
|
|
||||||
yield
|
|
||||||
out, err = self.suspendcapture()
|
out, err = self.suspendcapture()
|
||||||
item.add_report_section(when, "out", out)
|
item.add_report_section(when, "out", out)
|
||||||
item.add_report_section(when, "err", err)
|
item.add_report_section(when, "err", err)
|
||||||
|
|
|
@ -60,7 +60,6 @@ def pytest_addoption(parser):
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
genscript = config.getvalue("genscript")
|
genscript = config.getvalue("genscript")
|
||||||
if genscript:
|
if genscript:
|
||||||
#tw = config.get_terminal_writer()
|
|
||||||
tw = py.io.TerminalWriter()
|
tw = py.io.TerminalWriter()
|
||||||
deps = ['py', '_pytest', 'pytest']
|
deps = ['py', '_pytest', 'pytest']
|
||||||
if sys.version_info < (2,7):
|
if sys.version_info < (2,7):
|
||||||
|
|
|
@ -47,8 +47,6 @@ def pytest_unconfigure(config):
|
||||||
|
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
if config.option.version:
|
if config.option.version:
|
||||||
capman = config.pluginmanager.getplugin("capturemanager")
|
|
||||||
capman.reset_capturings()
|
|
||||||
p = py.path.local(pytest.__file__)
|
p = py.path.local(pytest.__file__)
|
||||||
sys.stderr.write("This is pytest version %s, imported from %s\n" %
|
sys.stderr.write("This is pytest version %s, imported from %s\n" %
|
||||||
(pytest.__version__, p))
|
(pytest.__version__, p))
|
||||||
|
@ -64,7 +62,7 @@ def pytest_cmdline_main(config):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def showhelp(config):
|
def showhelp(config):
|
||||||
tw = config.get_terminal_writer()
|
tw = py.io.TerminalWriter()
|
||||||
tw.write(config._parser.optparser.format_help())
|
tw.write(config._parser.optparser.format_help())
|
||||||
tw.line()
|
tw.line()
|
||||||
tw.line()
|
tw.line()
|
||||||
|
|
|
@ -40,7 +40,7 @@ def pytest_addoption(parser):
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
if config.option.markers:
|
if config.option.markers:
|
||||||
config.do_configure()
|
config.do_configure()
|
||||||
tw = config.get_terminal_writer()
|
tw = py.io.TerminalWriter()
|
||||||
for line in config.getini("markers"):
|
for line in config.getini("markers"):
|
||||||
name, rest = line.split(":", 1)
|
name, rest = line.split(":", 1)
|
||||||
tw.write("@pytest.mark.%s:" % name, bold=True)
|
tw.write("@pytest.mark.%s:" % name, bold=True)
|
||||||
|
|
|
@ -885,7 +885,7 @@ def _showfixtures_main(config, session):
|
||||||
nodeid = "::".join(map(str, [curdir.bestrelpath(part[0])] + part[1:]))
|
nodeid = "::".join(map(str, [curdir.bestrelpath(part[0])] + part[1:]))
|
||||||
nodeid.replace(session.fspath.sep, "/")
|
nodeid.replace(session.fspath.sep, "/")
|
||||||
|
|
||||||
tw = config.get_terminal_writer()
|
tw = py.io.TerminalWriter()
|
||||||
verbose = config.getvalue("verbose")
|
verbose = config.getvalue("verbose")
|
||||||
|
|
||||||
fm = session._fixturemanager
|
fm = session._fixturemanager
|
||||||
|
|
|
@ -36,10 +36,7 @@ def pytest_addoption(parser):
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
config.option.verbose -= config.option.quiet
|
config.option.verbose -= config.option.quiet
|
||||||
out = config.pluginmanager.getplugin("dupped_stdout")
|
reporter = TerminalReporter(config, sys.stdout)
|
||||||
#if out is None:
|
|
||||||
# out = sys.stdout
|
|
||||||
reporter = TerminalReporter(config, out)
|
|
||||||
config.pluginmanager.register(reporter, 'terminalreporter')
|
config.pluginmanager.register(reporter, 'terminalreporter')
|
||||||
if config.option.debug or config.option.traceconfig:
|
if config.option.debug or config.option.traceconfig:
|
||||||
def mywriter(tags, args):
|
def mywriter(tags, args):
|
||||||
|
@ -47,11 +44,6 @@ def pytest_configure(config):
|
||||||
reporter.write_line("[traceconfig] " + msg)
|
reporter.write_line("[traceconfig] " + msg)
|
||||||
config.trace.root.setprocessor("pytest:config", mywriter)
|
config.trace.root.setprocessor("pytest:config", mywriter)
|
||||||
|
|
||||||
def get_terminal_writer(config):
|
|
||||||
tr = config.pluginmanager.getplugin("terminalreporter")
|
|
||||||
return tr._tw
|
|
||||||
|
|
||||||
|
|
||||||
def getreportopt(config):
|
def getreportopt(config):
|
||||||
reportopts = ""
|
reportopts = ""
|
||||||
optvalue = config.option.report
|
optvalue = config.option.report
|
||||||
|
@ -104,7 +96,6 @@ class TerminalReporter:
|
||||||
self.startdir = self.curdir = py.path.local()
|
self.startdir = self.curdir = py.path.local()
|
||||||
if file is None:
|
if file is None:
|
||||||
file = py.std.sys.stdout
|
file = py.std.sys.stdout
|
||||||
#assert file.encoding
|
|
||||||
self._tw = self.writer = py.io.TerminalWriter(file)
|
self._tw = self.writer = py.io.TerminalWriter(file)
|
||||||
if self.config.option.color == 'yes':
|
if self.config.option.color == 'yes':
|
||||||
self._tw.hasmarkup = True
|
self._tw.hasmarkup = True
|
||||||
|
|
Loading…
Reference in New Issue