Skip to content

Commit 1672800

Browse files
author
goodboy
authored
Merge pull request #69 from tgoodlet/firstresult_is_none
Handle first result with None results
2 parents b289c9e + f1a2270 commit 1672800

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

pluggy/callers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def execute(self):
107107
pass
108108

109109
if firstresult:
110-
return outcome.get_result()[0]
110+
result = outcome.get_result()
111+
return result[0] if result else None
111112

112113
return outcome.get_result()
113114

testing/test_hookrelay.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,38 @@ def hello(self, arg):
9292
pm.register(Plugin3()) # None result is ignored
9393
res = pm.hook.hello(arg=3)
9494
assert res == 2
95+
96+
97+
def test_firstresult_returns_none(pm):
98+
"""If None results are returned by underlying implementations ensure
99+
the multi-call loop returns a None value.
100+
"""
101+
class Api(object):
102+
@hookspec(firstresult=True)
103+
def hello(self, arg):
104+
"api hook 1"
105+
106+
pm.add_hookspecs(Api)
107+
108+
class Plugin1(object):
109+
@hookimpl
110+
def hello(self, arg):
111+
return None
112+
113+
pm.register(Plugin1())
114+
res = pm.hook.hello(arg=3)
115+
assert res is None
116+
117+
118+
def test_firstresult_no_plugin(pm):
119+
"""If no implementations/plugins have been registered for a firstresult
120+
hook the multi-call loop should return a None value.
121+
"""
122+
class Api(object):
123+
@hookspec(firstresult=True)
124+
def hello(self, arg):
125+
"api hook 1"
126+
127+
pm.add_hookspecs(Api)
128+
res = pm.hook.hello(arg=3)
129+
assert res is None

0 commit comments

Comments
 (0)