From 4ab6b1fbd600e1917003b6d0eb5410c45f380320 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 16 Feb 2017 02:20:54 -0500 Subject: [PATCH] Add a call vs. spec mismatch warning test --- testing/test_details.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/testing/test_details.py b/testing/test_details.py index 51280122..e0f3cb9b 100644 --- a/testing/test_details.py +++ b/testing/test_details.py @@ -1,3 +1,4 @@ +import warnings from pluggy import PluginManager, HookimplMarker, HookspecMarker @@ -62,3 +63,33 @@ class Module(object): # register() would raise an error pm.register(module, 'donttouch') assert pm.get_plugin('donttouch') is module + + +def test_warning_on_call_vs_hookspec_arg_mismatch(): + """Verify that is a hook is called with less arguments then defined in the + spec that a warning is emitted. + """ + class Spec: + @hookspec + def myhook(self, arg1, arg2): + pass + + class Plugin: + @hookimpl + def myhook(self, arg1): + pass + + pm = PluginManager(hookspec.project_name) + pm.register(Plugin()) + pm.add_hookspecs(Spec()) + + with warnings.catch_warnings(record=True) as warns: + warnings.simplefilter('always') + + # calling should trigger a warning + pm.hook.myhook(arg1=1) + + assert len(warns) == 1 + warning = warns[-1] + assert issubclass(warning.category, Warning) + assert "Argument(s) ('arg2',)" in str(warning.message)