diff --git a/py/_io/terminalwriter.py b/py/_io/terminalwriter.py index 982d5a661..1d9b80f30 100644 --- a/py/_io/terminalwriter.py +++ b/py/_io/terminalwriter.py @@ -103,7 +103,6 @@ class TerminalWriter(object): # XXX deprecate stringio argument def __init__(self, file=None, stringio=False, encoding=None): - if file is None: if stringio: self.stringio = file = py.io.TextIO() diff --git a/py/_plugin/pytest_terminal.py b/py/_plugin/pytest_terminal.py index 78e49ac14..7be7e1be8 100644 --- a/py/_plugin/pytest_terminal.py +++ b/py/_plugin/pytest_terminal.py @@ -118,6 +118,7 @@ class TerminalReporter: def pytest_internalerror(self, excrepr): for line in str(excrepr).split("\n"): self.write_line("INTERNALERROR> " + line) + return 1 def pytest_plugin_registered(self, plugin): if self.config.option.traceconfig: diff --git a/py/_test/pluginmanager.py b/py/_test/pluginmanager.py index 89bd995b3..a00c51031 100644 --- a/py/_test/pluginmanager.py +++ b/py/_test/pluginmanager.py @@ -2,6 +2,7 @@ managing loading and interacting with pytest plugins. """ import py +import sys import inspect from py._plugin import hookspec @@ -163,7 +164,11 @@ class PluginManager(object): if excinfo is None: excinfo = py.code.ExceptionInfo() excrepr = excinfo.getrepr(funcargs=True, showlocals=True) - return self.hook.pytest_internalerror(excrepr=excrepr) + res = self.hook.pytest_internalerror(excrepr=excrepr) + if not py.builtin.any(res): + for line in str(excrepr).split("\n"): + sys.stderr.write("INTERNALERROR> %s\n" %line) + sys.stderr.flush() def do_addoption(self, parser): mname = "pytest_addoption" diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index dddf99d0b..b1d3a7148 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -214,6 +214,21 @@ class TestBootstrapping: for name in 'xyz', 'pytest_xyz', 'pytest_Xyz', 'Xyz': impname = canonical_importname(name) + def test_notify_exception(self, capfd): + pp = PluginManager() + excinfo = py.test.raises(ValueError, "raise ValueError(1)") + pp.notify_exception(excinfo) + out, err = capfd.readouterr() + assert "ValueError" in err + class A: + def pytest_internalerror(self, excrepr): + return True + pp.register(A()) + pp.notify_exception(excinfo) + out, err = capfd.readouterr() + assert not err + + class TestPytestPluginInteractions: def test_addhooks_conftestplugin(self, testdir):