Skip to content

Commit bbbb6dc

Browse files
committed
remove _do_register indirection between PluginManager and PytestPluginManager
--HG-- branch : more_plugin
1 parent f415284 commit bbbb6dc

3 files changed

Lines changed: 28 additions & 29 deletions

File tree

_pytest/config.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,13 @@ def __init__(self):
119119

120120
def register(self, plugin, name=None, conftest=False):
121121
ret = super(PytestPluginManager, self).register(plugin, name)
122-
if ret and not conftest:
123-
self._globalplugins.append(plugin)
122+
if ret:
123+
if not conftest:
124+
self._globalplugins.append(plugin)
125+
if hasattr(self, "config"):
126+
self.config._register_plugin(plugin, name)
124127
return ret
125128

126-
def _do_register(self, plugin, name):
127-
# called from core PluginManager class
128-
if hasattr(self, "config"):
129-
self.config._register_plugin(plugin, name)
130-
return super(PytestPluginManager, self)._do_register(plugin, name)
131-
132129
def unregister(self, plugin):
133130
super(PytestPluginManager, self).unregister(plugin)
134131
try:
@@ -710,8 +707,7 @@ def __init__(self, pluginmanager):
710707

711708
def _register_plugin(self, plugin, name):
712709
call_plugin = self.pluginmanager.call_plugin
713-
call_plugin(plugin, "pytest_addhooks",
714-
{'pluginmanager': self.pluginmanager})
710+
call_plugin(plugin, "pytest_addhooks", {'pluginmanager': self.pluginmanager})
715711
self.hook.pytest_plugin_registered(plugin=plugin,
716712
manager=self.pluginmanager)
717713
dic = call_plugin(plugin, "pytest_namespace", {}) or {}

_pytest/core.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ def register(self, plugin, name=None):
201201
raise ValueError("Plugin already registered: %s=%s\n%s" %(
202202
name, plugin, self._name2plugin))
203203
#self.trace("registering", name, plugin)
204-
# allow subclasses to intercept here by calling a helper
205-
return self._do_register(plugin, name)
206-
207-
def _do_register(self, plugin, name):
208204
self._plugin2hookcallers[plugin] = self._scan_plugin(plugin)
209205
self._name2plugin[name] = plugin
210206
self._plugins.append(plugin)

testing/test_core.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def he_method1(self, arg):
7777
#assert not pm._unverified_hooks
7878
assert pm.hook.he_method1(arg=1) == [2]
7979

80+
8081
class TestAddMethodOrdering:
8182
@pytest.fixture
8283
def hc(self, pm):
@@ -283,24 +284,30 @@ def test_hook_tracing(self):
283284
pytestpm = get_plugin_manager() # fully initialized with plugins
284285
saveindent = []
285286
class api1:
286-
x = 41
287287
def pytest_plugin_registered(self, plugin):
288288
saveindent.append(pytestpm.trace.root.indent)
289-
raise ValueError(42)
289+
class api2:
290+
def pytest_plugin_registered(self, plugin):
291+
saveindent.append(pytestpm.trace.root.indent)
292+
raise ValueError()
290293
l = []
291-
pytestpm.set_tracing(l.append)
292-
indent = pytestpm.trace.root.indent
293-
p = api1()
294-
pytestpm.register(p)
295-
296-
assert pytestpm.trace.root.indent == indent
297-
assert len(l) == 2
298-
assert 'pytest_plugin_registered' in l[0]
299-
assert 'finish' in l[1]
300-
with pytest.raises(ValueError):
301-
pytestpm.register(api1())
302-
assert pytestpm.trace.root.indent == indent
303-
assert saveindent[0] > indent
294+
undo = pytestpm.set_tracing(l.append)
295+
try:
296+
indent = pytestpm.trace.root.indent
297+
p = api1()
298+
pytestpm.register(p)
299+
assert pytestpm.trace.root.indent == indent
300+
assert len(l) == 2
301+
assert 'pytest_plugin_registered' in l[0]
302+
assert 'finish' in l[1]
303+
304+
l[:] = []
305+
with pytest.raises(ValueError):
306+
pytestpm.register(api2())
307+
assert pytestpm.trace.root.indent == indent
308+
assert saveindent[0] > indent
309+
finally:
310+
undo()
304311

305312

306313
def test_namespace_has_default_and_env_plugins(testdir):

0 commit comments

Comments
 (0)