diff --git a/src/pluggy/_manager.py b/src/pluggy/_manager.py index 8a0959f7..1d7984a9 100644 --- a/src/pluggy/_manager.py +++ b/src/pluggy/_manager.py @@ -440,7 +440,7 @@ def _verify_hook(self, hook: HookCaller, hookimpl: HookImpl) -> None: ) if hook.spec.warn_on_impl_args: - for hookimpl_argname in hookimpl.argnames: + for hookimpl_argname in hookimpl.argnames + hookimpl.kwargnames: argname_warning = hook.spec.warn_on_impl_args.get(hookimpl_argname) if argname_warning is not None: _warn_for_function(argname_warning, hookimpl.function) diff --git a/testing/test_details.py b/testing/test_details.py index 8df167f4..3a9858f8 100644 --- a/testing/test_details.py +++ b/testing/test_details.py @@ -128,6 +128,30 @@ def foo(self, old2, old1, new): assert record2.lineno == Plugin.foo.__code__.co_firstlineno +def test_warn_when_deprecated_args_with_defaults_specified() -> None: + warning = DeprecationWarning("old is deprecated") + + class Spec: + @hookspec(warn_on_impl_args={"old": warning}) + def foo(self, old=None, new=None): + raise NotImplementedError() + + class Plugin: + @hookimpl + def foo(self, old=None, new=None): + raise NotImplementedError() + + pm = PluginManager(hookspec.project_name) + pm.add_hookspecs(Spec) + + with pytest.warns(DeprecationWarning) as records: + pm.register(Plugin()) + (record,) = records + assert record.message is warning + assert record.filename == Plugin.foo.__code__.co_filename + assert record.lineno == Plugin.foo.__code__.co_firstlineno + + def test_plugin_getattr_raises_errors() -> None: """Pluggy must be able to handle plugins which raise weird exceptions when getattr() gets called (#11).