Commits

holger krekel  committed a22e396

refine printing of exceptions via the pluginmanager.
if there is no pytest_internalerror() hook acknowledging
receival we print the exception to sys.stderr. This helps
to see issues when there are failures in TerminalReporter
initialization.

  • Participants
  • Parent commits 4d677af

Comments (0)

Files changed (4)

File py/_io/terminalwriter.py

 
     # 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()

File py/_plugin/pytest_terminal.py

     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:

File py/_test/pluginmanager.py

 managing loading and interacting with pytest plugins.
 """
 import py
+import sys
 import inspect
 from py._plugin import hookspec
 
         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"

File testing/test_pluginmanager.py

         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):