Skip to content

Commit 20c352c

Browse files
author
Tyler Goodlet
committed
Remove duplicate 'firstresult' test
Remove `test_method_ordering.test_decorator_functional` as it is duplicate of an already incomplete test. Fix up `test_firstresult_definition` to be more more complete and actually test that when multiple hooks are registered for a spec marked with `firstresult` the first result is only ever returned. Fixes #61
1 parent 6689c91 commit 20c352c

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

testing/test_hookrelay.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,23 @@ def hello(self, arg):
6868

6969
pm.add_hookspecs(Api)
7070

71-
class Plugin(object):
71+
class Plugin1(object):
7272
@hookimpl
7373
def hello(self, arg):
7474
return arg + 1
7575

76-
pm.register(Plugin())
76+
class Plugin2(object):
77+
@hookimpl
78+
def hello(self, arg):
79+
return arg - 1
80+
81+
class Plugin3(object):
82+
@hookimpl
83+
def hello(self, arg):
84+
return None
85+
86+
pm.register(Plugin1()) # discarded - not the last registered plugin
87+
pm.register(Plugin2()) # used as result
88+
pm.register(Plugin3()) # None result is ignored
7789
res = pm.hook.hello(arg=3)
78-
assert res == 4
90+
assert res == 2

testing/test_method_ordering.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,6 @@ def he_myhook1(arg1):
180180
assert not hasattr(he_myhook1, name)
181181

182182

183-
def test_decorator_functional(pm):
184-
class HookSpec(object):
185-
@hookspec(firstresult=True)
186-
def he_myhook(self, arg1):
187-
""" add to arg1 """
188-
189-
pm.add_hookspecs(HookSpec)
190-
191-
class Plugin(object):
192-
@hookimpl()
193-
def he_myhook(self, arg1):
194-
return arg1 + 1
195-
196-
pm.register(Plugin())
197-
results = pm.hook.he_myhook(arg1=17)
198-
assert results == 18
199-
200-
201183
def test_load_setuptools_instantiation(monkeypatch, pm):
202184
pkg_resources = pytest.importorskip("pkg_resources")
203185

0 commit comments

Comments
 (0)