diff --git a/_pytest/config.py b/_pytest/config.py index d6837f0fa..5156f3603 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -119,16 +119,13 @@ class PytestPluginManager(PluginManager): def register(self, plugin, name=None, conftest=False): ret = super(PytestPluginManager, self).register(plugin, name) - if ret and not conftest: - self._globalplugins.append(plugin) + if ret: + if not conftest: + self._globalplugins.append(plugin) + if hasattr(self, "config"): + self.config._register_plugin(plugin, name) return ret - def _do_register(self, plugin, name): - # called from core PluginManager class - if hasattr(self, "config"): - self.config._register_plugin(plugin, name) - return super(PytestPluginManager, self)._do_register(plugin, name) - def unregister(self, plugin): super(PytestPluginManager, self).unregister(plugin) try: @@ -710,8 +707,7 @@ class Config(object): def _register_plugin(self, plugin, name): call_plugin = self.pluginmanager.call_plugin - call_plugin(plugin, "pytest_addhooks", - {'pluginmanager': self.pluginmanager}) + call_plugin(plugin, "pytest_addhooks", {'pluginmanager': self.pluginmanager}) self.hook.pytest_plugin_registered(plugin=plugin, manager=self.pluginmanager) dic = call_plugin(plugin, "pytest_namespace", {}) or {} diff --git a/_pytest/core.py b/_pytest/core.py index 0296edf75..51fb55d2b 100644 --- a/_pytest/core.py +++ b/_pytest/core.py @@ -201,10 +201,6 @@ class PluginManager(object): raise ValueError("Plugin already registered: %s=%s\n%s" %( name, plugin, self._name2plugin)) #self.trace("registering", name, plugin) - # allow subclasses to intercept here by calling a helper - return self._do_register(plugin, name) - - def _do_register(self, plugin, name): self._plugin2hookcallers[plugin] = self._scan_plugin(plugin) self._name2plugin[name] = plugin self._plugins.append(plugin) diff --git a/testing/test_core.py b/testing/test_core.py index d2b9b155e..4d03433a2 100644 --- a/testing/test_core.py +++ b/testing/test_core.py @@ -77,6 +77,7 @@ class TestPluginManager: #assert not pm._unverified_hooks assert pm.hook.he_method1(arg=1) == [2] + class TestAddMethodOrdering: @pytest.fixture def hc(self, pm): @@ -283,24 +284,30 @@ class TestPytestPluginInteractions: pytestpm = get_plugin_manager() # fully initialized with plugins saveindent = [] class api1: - x = 41 def pytest_plugin_registered(self, plugin): saveindent.append(pytestpm.trace.root.indent) - raise ValueError(42) + class api2: + def pytest_plugin_registered(self, plugin): + saveindent.append(pytestpm.trace.root.indent) + raise ValueError() l = [] - pytestpm.set_tracing(l.append) - indent = pytestpm.trace.root.indent - p = api1() - pytestpm.register(p) + undo = pytestpm.set_tracing(l.append) + try: + indent = pytestpm.trace.root.indent + p = api1() + pytestpm.register(p) + assert pytestpm.trace.root.indent == indent + assert len(l) == 2 + assert 'pytest_plugin_registered' in l[0] + assert 'finish' in l[1] - assert pytestpm.trace.root.indent == indent - assert len(l) == 2 - assert 'pytest_plugin_registered' in l[0] - assert 'finish' in l[1] - with pytest.raises(ValueError): - pytestpm.register(api1()) - assert pytestpm.trace.root.indent == indent - assert saveindent[0] > indent + l[:] = [] + with pytest.raises(ValueError): + pytestpm.register(api2()) + assert pytestpm.trace.root.indent == indent + assert saveindent[0] > indent + finally: + undo() def test_namespace_has_default_and_env_plugins(testdir):