Skip to content

Commit b77d7b3

Browse files
Add test for _remove_plugin ValueError on unknown plugin
Add test coverage for the error path in HookCaller._remove_plugin() when attempting to remove a plugin that isn't registered with the hook. This improves coverage from 99% to nearly 100%, with only defensive code remaining uncovered (isinstance check that's always true). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0a9e38b commit b77d7b3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

testing/test_pluginmanager.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,32 @@ class Plugin:
213213
pm.unregister(p, "error")
214214

215215

216+
def test_unregister_unknown_plugin_raises(pm: PluginManager) -> None:
217+
"""Test that _remove_plugin raises ValueError for unknown plugin."""
218+
219+
class Plugin1:
220+
@hookimpl
221+
def he_method1(self, arg):
222+
return arg + 1
223+
224+
class Plugin2:
225+
@hookimpl
226+
def he_method1(self, arg):
227+
return arg + 2
228+
229+
# Register Plugin1
230+
p1 = Plugin1()
231+
pm.register(p1)
232+
233+
# Create Plugin2 but don't register it
234+
p2 = Plugin2()
235+
236+
# Get the hook and try to remove the unregistered plugin directly
237+
hook = pm.hook.he_method1
238+
with pytest.raises(ValueError, match="plugin.*not found"):
239+
hook._remove_plugin(p2)
240+
241+
216242
def test_register_unknown_hooks(pm: PluginManager) -> None:
217243
class Plugin1:
218244
@hookimpl

0 commit comments

Comments
 (0)