Skip to content

Commit 366946a

Browse files
author
goodboy
authored
Merge pull request #122 from ids1024/PluginValidationError-plugin
Add .plugin member to PluginValidationError to access failing plugin
2 parents 956a7be + 2a2c971 commit 366946a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

pluggy/manager.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55

66
class PluginValidationError(Exception):
7-
""" plugin failed validation. """
7+
""" plugin failed validation.
8+
9+
:param object plugin: the plugin which failed validation, may be a module or an arbitrary object.
10+
"""
11+
12+
def __init__(self, plugin, message):
13+
self.plugin = plugin
14+
super(Exception, self).__init__(message)
815

916

1017
class PluginManager(object):
@@ -178,13 +185,15 @@ def get_name(self, plugin):
178185
def _verify_hook(self, hook, hookimpl):
179186
if hook.is_historic() and hookimpl.hookwrapper:
180187
raise PluginValidationError(
188+
hookimpl.plugin,
181189
"Plugin %r\nhook %r\nhistoric incompatible to hookwrapper" %
182190
(hookimpl.plugin_name, hook.name))
183191

184192
# positional arg checking
185193
notinspec = set(hookimpl.argnames) - set(hook.argnames)
186194
if notinspec:
187195
raise PluginValidationError(
196+
hookimpl.plugin,
188197
"Plugin %r for hook %r\nhookimpl definition: %s\n"
189198
"Argument(s) %s are declared in the hookimpl but "
190199
"can not be found in the hookspec" %
@@ -202,6 +211,7 @@ def check_pending(self):
202211
for hookimpl in (hook._wrappers + hook._nonwrappers):
203212
if not hookimpl.optionalhook:
204213
raise PluginValidationError(
214+
hookimpl.plugin,
205215
"unknown hook %r in plugin %r" %
206216
(name, hookimpl.plugin))
207217

testing/test_pluginmanager.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ class hello(object):
103103
def he_method_notexists(self):
104104
pass
105105

106-
he_pm.register(hello())
107-
with pytest.raises(PluginValidationError):
106+
plugin = hello()
107+
108+
he_pm.register(plugin)
109+
with pytest.raises(PluginValidationError) as excinfo:
108110
he_pm.check_pending()
111+
assert excinfo.value.plugin is plugin
109112

110113

111114
def test_register_mismatch_arg(he_pm):
@@ -114,8 +117,11 @@ class hello(object):
114117
def he_method1(self, qlwkje):
115118
pass
116119

117-
with pytest.raises(PluginValidationError):
118-
he_pm.register(hello())
120+
plugin = hello()
121+
122+
with pytest.raises(PluginValidationError) as excinfo:
123+
he_pm.register(plugin)
124+
assert excinfo.value.plugin is plugin
119125

120126

121127
def test_register(pm):

0 commit comments

Comments
 (0)