remove _do_register indirection between PluginManager and PytestPluginManager

--HG--
branch : more_plugin
This commit is contained in:
holger krekel 2015-04-25 11:29:11 +02:00
parent f41528433b
commit bbbb6dc2e3
3 changed files with 27 additions and 28 deletions

View File

@ -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 {}

View File

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

View File

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