Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HookImpl.__repr__ #156

Merged
merged 2 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pluggy/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,9 @@ def __init__(self, plugin, plugin_name, function, hook_impl_opts):
self.opts = hook_impl_opts
self.plugin_name = plugin_name
self.__dict__.update(hook_impl_opts)

def __repr__(self):
return "<HookImpl plugin_name=%r, plugin=%r>" % (
self.plugin_name,
self.plugin,
)
17 changes: 17 additions & 0 deletions testing/test_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,20 @@ def myhook(self, arg1):
warning = warns[-1]
assert issubclass(warning.category, Warning)
assert "Argument(s) ('arg2',)" in str(warning.message)


def test_repr():
class Plugin:
@hookimpl
def myhook():
raise NotImplementedError()

pm = PluginManager(hookspec.project_name)

plugin = Plugin()
pname = pm.register(plugin)
assert repr(pm.hook.myhook._nonwrappers[0]) == (
"<HookImpl plugin_name=%r, plugin=%r>" % (
pname,
plugin,
))