diff --git a/py/test/dist/dsession.py b/py/test/dist/dsession.py index 4f086fa8f..4620cabb0 100644 --- a/py/test/dist/dsession.py +++ b/py/test/dist/dsession.py @@ -140,7 +140,7 @@ class DSession(Session): except KeyboardInterrupt: exitstatus = outcome.EXIT_INTERRUPTED except: - self.bus.notify("internalerror", event.InternalException()) + self.config.pytestplugins.notify_exception() exitstatus = outcome.EXIT_INTERNALERROR self.config.bus.unregister(loopstate) if exitstatus == 0 and self._testsfailed: diff --git a/py/test/dist/testing/test_txnode.py b/py/test/dist/testing/test_txnode.py index 8d10f948f..fe1b84c7e 100644 --- a/py/test/dist/testing/test_txnode.py +++ b/py/test/dist/testing/test_txnode.py @@ -109,7 +109,7 @@ class TestMasterSlaveConnection: node = mysetup.makenode(item.config) node.channel.close() py.test.raises(IOError, "node.send(item)") - #ev = self.geteventargs(event.InternalException) + #ev = self.getevents("internalerror") #assert ev.excinfo.errisinstance(IOError) def test_send_one(self, testdir, mysetup): diff --git a/py/test/dist/txnode.py b/py/test/dist/txnode.py index 04772c2ad..4caba485c 100644 --- a/py/test/dist/txnode.py +++ b/py/test/dist/txnode.py @@ -63,7 +63,7 @@ class TXNode(object): except: excinfo = py.code.ExceptionInfo() print "!" * 20, excinfo - self.notify("internalerror", event.InternalException(excinfo)) + self.notify_internal(excinfo) def send(self, item): assert item is not None @@ -127,7 +127,8 @@ class SlaveNode(object): except KeyboardInterrupt: raise except: - self.sendevent("internalerror", event.InternalException()) + er = py.code.ExceptionInfo().getrepr(funcargs=True, showlocals=True) + self.sendevent("internalerror", excrepr=er) raise def runtest(self, item): diff --git a/py/test/event.py b/py/test/event.py index b62f53bca..f056c7a59 100644 --- a/py/test/event.py +++ b/py/test/event.py @@ -18,16 +18,6 @@ def timestamp(): class NOP(BaseEvent): pass -# ---------------------------------------------------------------------- -# Basic Live Reporting Events -# ---------------------------------------------------------------------- - -class InternalException(BaseEvent): - def __init__(self, excinfo=None): - if excinfo is None: - excinfo = py.code.ExceptionInfo() - self.repr = excinfo.getrepr(funcargs=True, showlocals=True) - # ---------------------------------------------------------------------- # Events related to collecting and executing test Items # ---------------------------------------------------------------------- @@ -35,7 +25,6 @@ class InternalException(BaseEvent): class Deselected(BaseEvent): def __init__(self, items): self.items = items - class BaseReport(BaseEvent): def toterminal(self, out): diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py index 0c0a2a0d9..80f47a533 100644 --- a/py/test/plugin/api.py +++ b/py/test/plugin/api.py @@ -73,7 +73,7 @@ class Events: def pyevent__trace(self, category, msg): """ called for tracing events. """ - def pyevent__internalerror(self, event): + def pyevent__internalerror(self, excrepr): """ called for internal errors. """ def pyevent__itemstart(self, item, node=None): diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index ef7a240c7..e3c78bfac 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.py @@ -264,7 +264,7 @@ class ParsedEvent: self.__dict__ = locals.copy() def __repr__(self): - return "" %(self.__dict__,) + return "" %(self.__dict__,) class EventRecorder(object): def __init__(self, pyplugins, debug=False): # True): @@ -288,6 +288,7 @@ class EventRecorder(object): raise KeyError("popevent: %r not found in %r" %(name, self.events)) def getevents(self, eventname): + """ return list of ParsedEvent instances matching the given eventname. """ method = self.geteventmethod(eventname) l = [] for event in self.events: diff --git a/py/test/plugin/pytest_resultdb.py b/py/test/plugin/pytest_resultdb.py index c95328e7d..05983d634 100644 --- a/py/test/plugin/pytest_resultdb.py +++ b/py/test/plugin/pytest_resultdb.py @@ -178,10 +178,10 @@ class ResultDB(object): if not event.passed: self.log_outcome(event) - def pyevent__internalerror(self, event): - path = event.repr.reprcrash.path # fishing :( - self.write_log_entry(event, '!', path, str(event.repr)) - + def pyevent__internalerror(self, excrepr): + path = excrepr.reprcrash.path + XXX # we don't have an event + self.write_log_entry(event, '!', path, str(excrepr)) SQL_CREATE_TABLES = """ create table pytest_results ( @@ -368,9 +368,9 @@ class TestWithFunctionIntegration: try: raise ValueError except ValueError: - excinfo = event.InternalException() + excinfo = py.code.ExceptionInfo() reslog = ResultDB(StringIO.StringIO()) - reslog.pyevent("internalerror", (excinfo,), {}) + reslog.pyevent("internalerror", (excinfo.getrepr(),), {}) entry = reslog.logfile.getvalue() entry_lines = entry.splitlines() diff --git a/py/test/plugin/pytest_resultlog.py b/py/test/plugin/pytest_resultlog.py index e4913b9ed..a9a2b18b7 100644 --- a/py/test/plugin/pytest_resultlog.py +++ b/py/test/plugin/pytest_resultlog.py @@ -90,8 +90,9 @@ class ResultLog(object): if not event.passed: self.log_outcome(event) elif eventname == "internalerror": - path = event.repr.reprcrash.path # fishing :( - self.write_log_entry('!', path, str(event.repr)) + excrepr = args[0] + path = excrepr.reprcrash.path # fishing :( + self.write_log_entry('!', path, str(excrepr)) # =============================================================================== @@ -224,9 +225,9 @@ class TestWithFunctionIntegration: try: raise ValueError except ValueError: - excinfo = event.InternalException() + excinfo = py.code.ExceptionInfo() reslog = ResultLog(StringIO.StringIO()) - reslog.pyevent("internalerror", (excinfo,), {}) + reslog.pyevent("internalerror", (excinfo.getrepr(),), {}) entry = reslog.logfile.getvalue() entry_lines = entry.splitlines() diff --git a/py/test/plugin/pytest_terminal.py b/py/test/plugin/pytest_terminal.py index 7ef8b2e9b..4a081d347 100644 --- a/py/test/plugin/pytest_terminal.py +++ b/py/test/plugin/pytest_terminal.py @@ -82,9 +82,9 @@ class TerminalReporter: else: return "???", dict(red=True) - def pyevent__internalerror(self, event): - for line in str(event.repr).split("\n"): - self.write_line("InternalException: " + line) + def pyevent__internalerror(self, excrepr): + for line in str(excrepr).split("\n"): + self.write_line("INTERNALERROR> " + line) def pyevent__gwmanage_newgateway(self, gateway, rinfo): #self.write_line("%s instantiated gateway from spec %r" %(gateway.id, gateway.spec._spec)) @@ -438,9 +438,9 @@ class TestTerminal: modcol = testdir.getmodulecol("def test_one(): pass") rep = TerminalReporter(modcol.config, file=linecomp.stringio) excinfo = py.test.raises(ValueError, "raise ValueError('hello')") - rep.pyevent__internalerror(event.InternalException(excinfo)) + rep.pyevent__internalerror(excinfo.getrepr()) linecomp.assert_contains_lines([ - "InternalException: >*raise ValueError*" + "INTERNALERROR> *raise ValueError*" ]) def test_gwmanage_events(self, testdir, linecomp): diff --git a/py/test/pytestplugin.py b/py/test/pytestplugin.py index 0ecefcb90..725479dd4 100644 --- a/py/test/pytestplugin.py +++ b/py/test/pytestplugin.py @@ -77,6 +77,12 @@ class PytestPlugins(object): def notify(self, eventname, *args, **kwargs): return self.pyplugins.notify(eventname, *args, **kwargs) + def notify_exception(self, excinfo=None): + if excinfo is None: + excinfo = py.code.ExceptionInfo() + excrepr = excinfo.getrepr(funcargs=True, showlocals=True) + return self.notify("internalerror", excrepr) + def do_addoption(self, parser): methods = self.pyplugins.listattr("pytest_addoption", reverse=True) mc = py._com.MultiCall(methods, parser=parser) diff --git a/py/test/session.py b/py/test/session.py index 2959257d9..95a80a25b 100644 --- a/py/test/session.py +++ b/py/test/session.py @@ -121,7 +121,7 @@ class Session(object): exitstatus = outcome.EXIT_INTERRUPTED except: captured_excinfo = py.code.ExceptionInfo() - self.bus.notify("internalerror", event.InternalException(captured_excinfo)) + self.config.pytestplugins.notify_exception(captured_excinfo) exitstatus = outcome.EXIT_INTERNALERROR if exitstatus == 0 and self._testsfailed: exitstatus = outcome.EXIT_TESTSFAILED