Skip to content

Commit 79631fd

Browse files
committed
test: cover pluggy.__version__ getattr and HookCaller._remove_plugin not-found path
Ran the suite under coverage.py and found two real gaps in otherwise near-100% covered code. The module-level __getattr__ that lazily resolves pluggy.__version__ via importlib.metadata (added per changelog/590.trivial.rst) had no test exercising either branch. And HookCaller._remove_plugin's ValueError, raised when asked to remove a plugin that never registered on that hook, was untested even though the normal removal path is well covered through PluginManager.unregister.
1 parent f632a4d commit 79631fd

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

testing/test_details.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ def test_dist_facade_identity_equality_and_hash() -> None:
230230
assert {fc1: "ok"}[fc1] == "ok"
231231

232232

233+
def test_dunder_version() -> None:
234+
assert pluggy.__version__ == distribution("pluggy").version
235+
236+
237+
def test_dunder_getattr_missing_raises() -> None:
238+
with pytest.raises(AttributeError, match="module pluggy has no attribute 'nope'"):
239+
pluggy.nope
240+
241+
233242
def test_hookimpl_disallow_invalid_combination() -> None:
234243
decorator = hookspec(historic=True, firstresult=True)
235244
with pytest.raises(ValueError, match="cannot have a historic firstresult hook"):

testing/test_hookcaller.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,25 @@ def extra2() -> str:
511511
"2",
512512
"3",
513513
]
514+
515+
516+
def test_remove_plugin_not_found_raises(hc: HookCaller, pm: PluginManager) -> None:
517+
"""_remove_plugin() raises ValueError for a plugin that never registered
518+
an implementation on this particular hook caller."""
519+
520+
class Plugin:
521+
@hookimpl
522+
def he_method1(self, arg):
523+
pass # pragma: no cover
524+
525+
plugin = Plugin()
526+
pm.register(plugin)
527+
assert len(hc.get_hookimpls()) == 1
528+
529+
other = Plugin()
530+
with pytest.raises(ValueError, match=f"plugin {other!r} not found"):
531+
hc._remove_plugin(other)
532+
533+
# the failed removal must not have touched the existing registration
534+
assert len(hc.get_hookimpls()) == 1
535+
pm.unregister(plugin)

0 commit comments

Comments
 (0)