Skip to content

Commit dea1c96

Browse files
committed
actually revert back to using older simpler method for subset hook
calling. It is slightly more inefficient but easier to implement and read. --HG-- branch : more_plugin
1 parent d2ea738 commit dea1c96

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

_pytest/core.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,19 @@ def subset_hook_caller(self, name, remove_plugins):
242242
""" Return a new HookCaller instance for the named method
243243
which manages calls to all registered plugins except the
244244
ones from remove_plugins. """
245-
hc = getattr(self.hook, name)
245+
orig = getattr(self.hook, name)
246246
plugins_to_remove = [plugin for plugin in remove_plugins
247247
if hasattr(plugin, name)]
248248
if plugins_to_remove:
249-
hc = hc.clone()
250-
for plugin in plugins_to_remove:
251-
hc._remove_plugin(plugin)
252-
return hc
249+
hc = HookCaller(orig.name, orig._hookexec, orig._specmodule_or_class)
250+
for plugin in orig._plugins:
251+
if plugin not in plugins_to_remove:
252+
hc._add_plugin(plugin)
253+
# we also keep track of this hook caller so it
254+
# gets properly removed on plugin unregistration
255+
self._plugin2hookcallers.setdefault(plugin, []).append(hc)
256+
return hc
257+
return orig
253258

254259
def get_canonical_name(self, plugin):
255260
""" Return canonical name for a plugin object. """
@@ -488,7 +493,6 @@ def __init__(self, name, hook_execute, specmodule_or_class=None):
488493
self._wrappers = []
489494
self._nonwrappers = []
490495
self._hookexec = hook_execute
491-
self._subcaller = []
492496
if specmodule_or_class is not None:
493497
self.set_specification(specmodule_or_class)
494498

@@ -506,21 +510,6 @@ def set_specification(self, specmodule_or_class):
506510
if hasattr(specfunc, "historic"):
507511
self._call_history = []
508512

509-
def clone(self):
510-
assert not self.is_historic()
511-
hc = object.__new__(HookCaller)
512-
hc.name = self.name
513-
hc._plugins = list(self._plugins)
514-
hc._wrappers = list(self._wrappers)
515-
hc._nonwrappers = list(self._nonwrappers)
516-
hc._hookexec = self._hookexec
517-
hc.argnames = self.argnames
518-
hc.firstresult = self.firstresult
519-
# we keep track of this hook caller so it
520-
# gets properly pruned on plugin unregistration
521-
self._subcaller.append(hc)
522-
return hc
523-
524513
def is_historic(self):
525514
return hasattr(self, "_call_history")
526515

@@ -531,10 +520,6 @@ def _remove_plugin(self, plugin):
531520
self._nonwrappers.remove(meth)
532521
except ValueError:
533522
self._wrappers.remove(meth)
534-
if hasattr(self, "_subcaller"):
535-
for hc in self._subcaller:
536-
if plugin in hc._plugins:
537-
hc._remove_plugin(plugin)
538523

539524
def _add_plugin(self, plugin):
540525
self._plugins.append(plugin)
@@ -553,6 +538,7 @@ def _add_method(self, meth):
553538
i = len(nonwrappers) - 1
554539
while i >= 0 and hasattr(nonwrappers[i], "tryfirst"):
555540
i -= 1
541+
556542
# and insert right in front of the tryfirst ones
557543
nonwrappers.insert(i+1, meth)
558544

0 commit comments

Comments
 (0)