remove _do_register indirection between PluginManager and PytestPluginManager
--HG-- branch : more_plugin
This commit is contained in:
parent
f41528433b
commit
bbbb6dc2e3
|
@ -119,15 +119,12 @@ class PytestPluginManager(PluginManager):
|
||||||
|
|
||||||
def register(self, plugin, name=None, conftest=False):
|
def register(self, plugin, name=None, conftest=False):
|
||||||
ret = super(PytestPluginManager, self).register(plugin, name)
|
ret = super(PytestPluginManager, self).register(plugin, name)
|
||||||
if ret and not conftest:
|
if ret:
|
||||||
|
if not conftest:
|
||||||
self._globalplugins.append(plugin)
|
self._globalplugins.append(plugin)
|
||||||
return ret
|
|
||||||
|
|
||||||
def _do_register(self, plugin, name):
|
|
||||||
# called from core PluginManager class
|
|
||||||
if hasattr(self, "config"):
|
if hasattr(self, "config"):
|
||||||
self.config._register_plugin(plugin, name)
|
self.config._register_plugin(plugin, name)
|
||||||
return super(PytestPluginManager, self)._do_register(plugin, name)
|
return ret
|
||||||
|
|
||||||
def unregister(self, plugin):
|
def unregister(self, plugin):
|
||||||
super(PytestPluginManager, self).unregister(plugin)
|
super(PytestPluginManager, self).unregister(plugin)
|
||||||
|
@ -710,8 +707,7 @@ class Config(object):
|
||||||
|
|
||||||
def _register_plugin(self, plugin, name):
|
def _register_plugin(self, plugin, name):
|
||||||
call_plugin = self.pluginmanager.call_plugin
|
call_plugin = self.pluginmanager.call_plugin
|
||||||
call_plugin(plugin, "pytest_addhooks",
|
call_plugin(plugin, "pytest_addhooks", {'pluginmanager': self.pluginmanager})
|
||||||
{'pluginmanager': self.pluginmanager})
|
|
||||||
self.hook.pytest_plugin_registered(plugin=plugin,
|
self.hook.pytest_plugin_registered(plugin=plugin,
|
||||||
manager=self.pluginmanager)
|
manager=self.pluginmanager)
|
||||||
dic = call_plugin(plugin, "pytest_namespace", {}) or {}
|
dic = call_plugin(plugin, "pytest_namespace", {}) or {}
|
||||||
|
|
|
@ -201,10 +201,6 @@ class PluginManager(object):
|
||||||
raise ValueError("Plugin already registered: %s=%s\n%s" %(
|
raise ValueError("Plugin already registered: %s=%s\n%s" %(
|
||||||
name, plugin, self._name2plugin))
|
name, plugin, self._name2plugin))
|
||||||
#self.trace("registering", name, plugin)
|
#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._plugin2hookcallers[plugin] = self._scan_plugin(plugin)
|
||||||
self._name2plugin[name] = plugin
|
self._name2plugin[name] = plugin
|
||||||
self._plugins.append(plugin)
|
self._plugins.append(plugin)
|
||||||
|
|
|
@ -77,6 +77,7 @@ class TestPluginManager:
|
||||||
#assert not pm._unverified_hooks
|
#assert not pm._unverified_hooks
|
||||||
assert pm.hook.he_method1(arg=1) == [2]
|
assert pm.hook.he_method1(arg=1) == [2]
|
||||||
|
|
||||||
|
|
||||||
class TestAddMethodOrdering:
|
class TestAddMethodOrdering:
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hc(self, pm):
|
def hc(self, pm):
|
||||||
|
@ -283,24 +284,30 @@ class TestPytestPluginInteractions:
|
||||||
pytestpm = get_plugin_manager() # fully initialized with plugins
|
pytestpm = get_plugin_manager() # fully initialized with plugins
|
||||||
saveindent = []
|
saveindent = []
|
||||||
class api1:
|
class api1:
|
||||||
x = 41
|
|
||||||
def pytest_plugin_registered(self, plugin):
|
def pytest_plugin_registered(self, plugin):
|
||||||
saveindent.append(pytestpm.trace.root.indent)
|
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 = []
|
l = []
|
||||||
pytestpm.set_tracing(l.append)
|
undo = pytestpm.set_tracing(l.append)
|
||||||
|
try:
|
||||||
indent = pytestpm.trace.root.indent
|
indent = pytestpm.trace.root.indent
|
||||||
p = api1()
|
p = api1()
|
||||||
pytestpm.register(p)
|
pytestpm.register(p)
|
||||||
|
|
||||||
assert pytestpm.trace.root.indent == indent
|
assert pytestpm.trace.root.indent == indent
|
||||||
assert len(l) == 2
|
assert len(l) == 2
|
||||||
assert 'pytest_plugin_registered' in l[0]
|
assert 'pytest_plugin_registered' in l[0]
|
||||||
assert 'finish' in l[1]
|
assert 'finish' in l[1]
|
||||||
|
|
||||||
|
l[:] = []
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
pytestpm.register(api1())
|
pytestpm.register(api2())
|
||||||
assert pytestpm.trace.root.indent == indent
|
assert pytestpm.trace.root.indent == indent
|
||||||
assert saveindent[0] > indent
|
assert saveindent[0] > indent
|
||||||
|
finally:
|
||||||
|
undo()
|
||||||
|
|
||||||
|
|
||||||
def test_namespace_has_default_and_env_plugins(testdir):
|
def test_namespace_has_default_and_env_plugins(testdir):
|
||||||
|
|
Loading…
Reference in New Issue