Skip to content

Commit 61b3884

Browse files
author
Tyler Goodlet
committed
Add a call vs. spec mismatch warning test
1 parent e52f039 commit 61b3884

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

testing/test_details.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from pluggy import PluginManager, HookimplMarker, HookspecMarker
23

34

@@ -62,3 +63,33 @@ class Module:
6263
# register() would raise an error
6364
pm.register(module, 'donttouch')
6465
assert pm.get_plugin('donttouch') is module
66+
67+
68+
def test_warning_on_call_vs_hookspec_arg_mismatch():
69+
"""Verify that is a hook is called with less arguments then defined in the
70+
spec that a warning is emitted.
71+
"""
72+
class Spec:
73+
@hookspec
74+
def myhook(self, arg1, arg2):
75+
pass
76+
77+
class Plugin:
78+
@hookimpl
79+
def myhook(self, arg1):
80+
pass
81+
82+
pm = PluginManager(hookspec.project_name)
83+
pm.register(Plugin())
84+
pm.add_hookspecs(Spec())
85+
86+
with warnings.catch_warnings(record=True) as warns:
87+
warnings.simplefilter('always')
88+
89+
# calling should trigger a warning
90+
pm.hook.myhook(arg1=1)
91+
92+
assert len(warns) == 1
93+
warning = warns[-1]
94+
assert issubclass(warning.category, Warning)
95+
assert "Argument(s) ('arg2',)" in str(warning.message)

0 commit comments

Comments
 (0)