File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ import warnings
1
2
from pluggy import PluginManager , HookimplMarker , HookspecMarker
2
3
3
4
@@ -62,3 +63,33 @@ class Module:
62
63
# register() would raise an error
63
64
pm .register (module , 'donttouch' )
64
65
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 )
You can’t perform that action at this time.
0 commit comments