Skip to content

Commit

Permalink
Add a call vs. spec mismatch warning test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Goodlet committed Feb 18, 2017
1 parent 96b6494 commit 4ab6b1f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions testing/test_details.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from pluggy import PluginManager, HookimplMarker, HookspecMarker


Expand Down Expand Up @@ -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)

0 comments on commit 4ab6b1f

Please sign in to comment.