From 73529ce63dd2c10b24c59af0e4be2798f72d7236 Mon Sep 17 00:00:00 2001 From: hpk Date: Thu, 9 Apr 2009 20:39:59 +0200 Subject: [PATCH] [svn r63911] striking unneeded call_each from pluginmanager --HG-- branch : trunk --- py/test/collect.py | 3 +-- py/test/plugin/api.py | 1 + py/test/plugin/pytest__pytest.py | 6 +++--- py/test/pluginmanager.py | 16 ++++++++-------- py/test/testing/test_pluginmanager.py | 19 +------------------ 5 files changed, 14 insertions(+), 31 deletions(-) diff --git a/py/test/collect.py b/py/test/collect.py index 196725af7..cb95cdf66 100644 --- a/py/test/collect.py +++ b/py/test/collect.py @@ -443,8 +443,7 @@ class Directory(FSCollector): def consider_dir(self, path, usefilters=None): if usefilters is not None: APIWARN("0.99", "usefilters argument not needed") - res = self.config.pluginmanager.call_firstresult( - 'pytest_collect_recurse', path=path, parent=self) + res = self.config.api.pytest_collect_recurse(path=path, parent=self) if res is None or res: return self.config.api.pytest_collect_directory( path=path, parent=self) diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py index 83188a263..8a7618c23 100644 --- a/py/test/plugin/api.py +++ b/py/test/plugin/api.py @@ -44,6 +44,7 @@ class PluginHooks: """ return True/False to cause/prevent recursion into given directory. return None if you do not want to make the decision. """ + pytest_collect_recurse.firstresult = True def pytest_collect_directory(self, path, parent): """ return Collection node or None. """ diff --git a/py/test/plugin/pytest__pytest.py b/py/test/plugin/pytest__pytest.py index ed0e1d582..7724b4dde 100644 --- a/py/test/plugin/pytest__pytest.py +++ b/py/test/plugin/pytest__pytest.py @@ -106,7 +106,7 @@ def test_callrecorder_basic(): def xyz(self, arg): pass rec.start_recording(ApiClass) - comregistry.call_each("xyz", 123) + rec.api.xyz(arg=123) call = rec.popcall("xyz") assert call.arg == 123 assert call._name == "xyz" @@ -124,7 +124,7 @@ def test_functional(testdir, linecomp): def xyz(self, arg): return arg + 1 rec._comregistry.register(Plugin()) - res = rec._comregistry.call_firstresult("xyz", 41) - assert res == 42 + res = rec.api.xyz(arg=41) + assert res == [42] """) sorter.assertoutcome(passed=1) diff --git a/py/test/pluginmanager.py b/py/test/pluginmanager.py index 48c61a0a0..b2aa238d6 100644 --- a/py/test/pluginmanager.py +++ b/py/test/pluginmanager.py @@ -79,16 +79,12 @@ class PluginManager(object): for x in self.comregistry.listattr(attrname): return x - def listattr(self, attrname): - return self.comregistry.listattr(attrname) + def listattr(self, attrname, plugins=None): + return self.comregistry.listattr(attrname, plugins=plugins) def call_firstresult(self, *args, **kwargs): return self.comregistry.call_firstresult(*args, **kwargs) - def call_each(self, *args, **kwargs): - #print "plugins.call_each", args[0], args[1:], kwargs - return self.comregistry.call_each(*args, **kwargs) - def notify_exception(self, excinfo=None): if excinfo is None: excinfo = py.code.ExceptionInfo() @@ -102,8 +98,12 @@ class PluginManager(object): def pytest_plugin_registered(self, plugin): if hasattr(self, '_config'): - self.comregistry.call_plugin(plugin, "pytest_addoption", parser=self._config._parser) - self.comregistry.call_plugin(plugin, "pytest_configure", config=self._config) + self.call_plugin(plugin, "pytest_addoption", parser=self._config._parser) + self.call_plugin(plugin, "pytest_configure", config=self._config) + + def call_plugin(self, plugin, methname, **kwargs): + return self.MultiCall(self.listattr(methname, plugins=[plugin]), + **kwargs).execute(firstresult=True) def do_configure(self, config): assert not hasattr(self, '_config') diff --git a/py/test/testing/test_pluginmanager.py b/py/test/testing/test_pluginmanager.py index 9d4ad7448..6e349ff12 100644 --- a/py/test/testing/test_pluginmanager.py +++ b/py/test/testing/test_pluginmanager.py @@ -172,12 +172,9 @@ class TestPytestPluginInteractions: def test_configure(self, testdir): config = testdir.parseconfig() l = [] - events = [] class A: def pytest_configure(self, config): l.append(self) - def xyz(self, obj): - events.append(obj) config.pluginmanager.register(A()) assert len(l) == 0 @@ -186,11 +183,7 @@ class TestPytestPluginInteractions: config.pluginmanager.register(A()) # this should lead to a configured() plugin assert len(l) == 2 assert l[0] != l[1] - - config.pluginmanager.call_each("xyz", obj=42) - assert len(events) == 2 - assert events == [42,42] - + config.pluginmanager.do_unconfigure(config=config) config.pluginmanager.register(A()) assert len(l) == 2 @@ -209,16 +202,6 @@ class TestPytestPluginInteractions: pluginmanager.register(My1()) assert pluginmanager.getfirst("x") == 1 - def test_call_each(self): - pluginmanager = PluginManager() - class My: - def method(self, arg): - pass - pluginmanager.register(My()) - py.test.raises(TypeError, 'pluginmanager.call_each("method")') - l = pluginmanager.call_each("method", arg=42) - assert l == [] - py.test.raises(TypeError, 'pluginmanager.call_each("method", arg=42, s=13)') def test_call_firstresult(self): pluginmanager = PluginManager()