Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,6 @@ def subset_hook_caller(
calls all registered plugins except the ones from remove_plugins."""
orig: HookCaller = getattr(self.hook, name)
plugins_to_remove = set(remove_plugins)
# Optimization: discard plugins to remove which don't actually implement
# the hook, to make checks faster.
plugins_to_remove.intersection_update(
hookimpl.plugin for hookimpl in orig._hookimpls
)
# Optimization: if none of the plugins to remove actually implement the
# hook, avoid the subset hook caller overhead.
if not plugins_to_remove:
return orig
return _SubsetHookCaller(orig, plugins_to_remove)
Expand Down
21 changes: 21 additions & 0 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,27 @@ class PluginNo:
assert repr(hc) == "<_SubsetHookCaller 'he_method1'>"


def test_subset_hook_caller_excludes_late_registered_plugin(pm: PluginManager) -> None:
class Hooks:
@hookspec
def he_method1(self):
pass

pm.add_hookspecs(Hooks)

class Plugin1:
@hookimpl
def he_method1(self):
return 1

plugin1 = Plugin1()
hc = pm.subset_hook_caller("he_method1", [plugin1])
pm.register(plugin1)

assert hc() == []
assert repr(hc) == "<_SubsetHookCaller 'he_method1'>"


def test_subset_hook_caller_with_specname(pm: PluginManager) -> None:
"""Test that subset_hook_caller doesn't get confused by specname."""

Expand Down