diff --git a/py/test/config.py b/py/test/config.py index 6d15942a4..d81058a76 100644 --- a/py/test/config.py +++ b/py/test/config.py @@ -42,7 +42,7 @@ class Config(object): self.pytestplugins = pytestplugins self._conftest = Conftest(onimport=self._onimportconftest) self._setupstate = SetupState() - self.api = pytestplugins._getapi() + self.api = pytestplugins.api def _onimportconftest(self, conftestmodule): self.trace("loaded conftestmodule %r" %(conftestmodule,)) diff --git a/py/test/dist/nodemanage.py b/py/test/dist/nodemanage.py index b499d4bd7..b9fabb4ab 100644 --- a/py/test/dist/nodemanage.py +++ b/py/test/dist/nodemanage.py @@ -15,7 +15,7 @@ class NodeManager(object): self._nodesready = py.std.threading.Event() def trace(self, msg): - self.config.bus.notify("trace", "nodemanage", msg) + self.config.api.pytest_trace(category="nodemanage", msg=msg) def config_getignores(self): return self.config.getconftest_pathlist("rsyncignore") diff --git a/py/test/dist/testing/test_dsession.py b/py/test/dist/testing/test_dsession.py index cf2d05796..c292b55d1 100644 --- a/py/test/dist/testing/test_dsession.py +++ b/py/test/dist/testing/test_dsession.py @@ -198,15 +198,6 @@ class TestDSession: session.loop_once(loopstate) assert len(session.node2pending) == 1 - def test_event_propagation(self, testdir): - item = testdir.getitem("def test_func(): pass") - session = DSession(item.config) - - evrec = testdir.geteventrecorder(session.bus) - session.queueevent("NOP", 42) - session.loop_once(session._initloopstate([])) - assert evrec.getcall('NOP') - def runthrough(self, item): session = DSession(item.config) node = MockNode() diff --git a/py/test/dist/testing/test_nodemanage.py b/py/test/dist/testing/test_nodemanage.py index 7df026814..b6ba51221 100644 --- a/py/test/dist/testing/test_nodemanage.py +++ b/py/test/dist/testing/test_nodemanage.py @@ -104,11 +104,10 @@ class TestNodeManager: config = py.test.config._reparse([source, '--debug']) assert config.option.debug nodemanager = NodeManager(config, specs) - sorter = testdir.geteventrecorder(config.bus) + sorter = testdir.geteventrecorder(config.bus).callrecorder nodemanager.setup_nodes(putevent=[].append) for spec in nodemanager.gwmanager.specs: - l = sorter.getcalls("trace") - print sorter.events + l = sorter.getcalls("pytest_trace") assert l nodemanager.teardown_nodes() diff --git a/py/test/dist/testing/test_txnode.py b/py/test/dist/testing/test_txnode.py index 1e11bf107..ebaaa04f3 100644 --- a/py/test/dist/testing/test_txnode.py +++ b/py/test/dist/testing/test_txnode.py @@ -9,9 +9,6 @@ class EventQueue: self.queue = queue bus.register(self) - def pyevent(self, eventname, args, kwargs): - self.queue.put((eventname, args, kwargs)) - def geteventargs(self, eventname, timeout=2.0): events = [] while 1: @@ -30,7 +27,7 @@ class EventQueue: return args return kwargs events.append(name) - if name == "internalerror": + if name == "pytest_internalerror": print str(kwargs["excrepr"]) class MySetup: @@ -113,7 +110,7 @@ class TestMasterSlaveConnection: node = mysetup.makenode(item.config) node.channel.close() py.test.raises(IOError, "node.send(item)") - #ev = self.getcalls("internalerror") + #ev = self.getcalls(pytest_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 0a5645047..5b3b21240 100644 --- a/py/test/dist/txnode.py +++ b/py/test/dist/txnode.py @@ -130,5 +130,5 @@ class SlaveNode(object): raise except: er = py.code.ExceptionInfo().getrepr(funcargs=True, showlocals=True) - self.sendevent("internalerror", excrepr=er) + self.sendevent("pytest_internalerror", excrepr=er) raise diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py index d5a7eb836..987c8a5e0 100644 --- a/py/test/plugin/api.py +++ b/py/test/plugin/api.py @@ -113,19 +113,9 @@ class PluginHooks: def pytest_looponfailinfo(self, failreports, rootdirs): """ info for repeating failing tests. """ - -class Events: - # Events - def pyevent(self, eventname, args, kwargs): - """ generically called for each notification event. """ - - def pyevent__NOP(self, *args, **kwargs): - """ the no-operation call. """ - - def pyevent__trace(self, category, msg): - """ called for tracing events. """ - - def pyevent__internalerror(self, excrepr): + def pytest_internalerror(self, excrepr): """ called for internal errors. """ + def pytest_trace(self, category, msg): + """ called for tracing events. """ diff --git a/py/test/plugin/pytest_plugintester.py b/py/test/plugin/pytest_plugintester.py index 11380009b..bd04c5c86 100644 --- a/py/test/plugin/pytest_plugintester.py +++ b/py/test/plugin/pytest_plugintester.py @@ -45,7 +45,6 @@ class PluginTester(Support): pm = py.test._PytestPlugins() methods = collectattr(pluginclass) hooks = collectattr(api.PluginHooks) - hooks.update(collectattr(api.Events)) getargs = py.std.inspect.getargs def isgenerichook(name): @@ -78,7 +77,7 @@ class PluginTester(Support): if fail: py.test.fail("Plugin API error") -def collectattr(obj, prefixes=("pytest_", "pyevent__")): +def collectattr(obj, prefixes=("pytest_",)): methods = {} for apiname in vars(obj): for prefix in prefixes: diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index bf474e89f..d8747f191 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.py @@ -285,13 +285,6 @@ class EventRecorder(object): self.debug = debug pyplugins.register(self) - def pyevent(self, name, args, kwargs): - if name == "plugin_registered" and args == (self,): - return - if self.debug: - print "[event: %s]: %s **%s" %(name, ", ".join(map(str, args)), kwargs,) - self.events.append(Event(name, args, kwargs)) - def popcall(self, name): for i, event in py.builtin.enumerate(self.events): if event.name == name: diff --git a/py/test/plugin/pytest_resultdb.py b/py/test/plugin/pytest_resultdb.py index 8190932cb..0e90200bc 100644 --- a/py/test/plugin/pytest_resultdb.py +++ b/py/test/plugin/pytest_resultdb.py @@ -349,7 +349,7 @@ class TestWithFunctionIntegration: except ValueError: excinfo = py.code.ExceptionInfo() reslog = ResultDB(StringIO.StringIO()) - reslog.pyevent__internalerror(excinfo.getrepr) + reslog.pytest_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 9b25d24a8..8c22d3b82 100644 --- a/py/test/plugin/pytest_resultlog.py +++ b/py/test/plugin/pytest_resultlog.py @@ -78,7 +78,7 @@ class ResultLog(object): longrepr = str(rep.longrepr.reprcrash) self.log_outcome(rep, code, longrepr) - def pyevent__internalerror(self, excrepr): + def pytest_internalerror(self, excrepr): path = excrepr.reprcrash.path self.write_log_entry(path, '!', str(excrepr)) @@ -214,7 +214,7 @@ class TestWithFunctionIntegration: except ValueError: excinfo = py.code.ExceptionInfo() reslog = ResultLog(StringIO.StringIO()) - reslog.pyevent__internalerror(excinfo.getrepr()) + reslog.pytest_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 70cd26e2b..4a8e5b64e 100644 --- a/py/test/plugin/pytest_terminal.py +++ b/py/test/plugin/pytest_terminal.py @@ -82,7 +82,7 @@ class TerminalReporter: else: return "???", dict(red=True) - def pyevent__internalerror(self, excrepr): + def pytest_internalerror(self, excrepr): for line in str(excrepr).split("\n"): self.write_line("INTERNALERROR> " + line) @@ -131,7 +131,7 @@ class TerminalReporter: if error: self.write_line("%s node down, error: %s" %(node.gateway.id, error)) - def pyevent__trace(self, category, msg): + def pytest_trace(self, category, msg): if self.config.option.debug or \ self.config.option.traceconfig and category.find("config") != -1: self.write_line("[%s] %s" %(category, msg)) @@ -437,7 +437,7 @@ 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(excinfo.getrepr()) + rep.pytest_internalerror(excinfo.getrepr()) linecomp.assert_contains_lines([ "INTERNALERROR> *raise ValueError*" ]) diff --git a/py/test/pytestplugin.py b/py/test/pytestplugin.py index 1b4886481..4365841c1 100644 --- a/py/test/pytestplugin.py +++ b/py/test/pytestplugin.py @@ -12,9 +12,9 @@ class PytestPlugins(object): self.MultiCall = self.pyplugins.MultiCall self._plugins = {} - def _getapi(self): - return py._com.PluginAPI(apiclass=api.PluginHooks, - plugins=self.pyplugins) + self.api = py._com.PluginAPI( + apiclass=api.PluginHooks, + plugins=self.pyplugins) def register(self, plugin): self.pyplugins.register(plugin) @@ -86,7 +86,7 @@ class PytestPlugins(object): if excinfo is None: excinfo = py.code.ExceptionInfo() excrepr = excinfo.getrepr(funcargs=True, showlocals=True) - return self.notify("internalerror", excrepr=excrepr) + return self.api.pytest_internalerror(excrepr=excrepr) def do_addoption(self, parser): methods = self.pyplugins.listattr("pytest_addoption", reverse=True) diff --git a/py/test/testing/test_pytestplugin.py b/py/test/testing/test_pytestplugin.py index b24bffd15..1b816372c 100644 --- a/py/test/testing/test_pytestplugin.py +++ b/py/test/testing/test_pytestplugin.py @@ -176,7 +176,7 @@ class TestPytestPluginInteractions: class A: def pytest_configure(self, config): l.append(self) - def pyevent__hello(self, obj): + def xyz(self, obj): events.append(obj) config.bus.register(A()) @@ -187,7 +187,7 @@ class TestPytestPluginInteractions: assert len(l) == 2 assert l[0] != l[1] - config.bus.notify("hello", 42) + config.bus.call_each("xyz", obj=42) assert len(events) == 2 assert events == [42,42]