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

Handle first result with None results #69

Merged
merged 2 commits into from
Aug 29, 2017
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
3 changes: 2 additions & 1 deletion pluggy/callers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ def execute(self):
pass

if firstresult:
return outcome.get_result()[0]
result = outcome.get_result()
return result[0] if result else None

return outcome.get_result()

Expand Down
35 changes: 35 additions & 0 deletions testing/test_hookrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,38 @@ def hello(self, arg):
pm.register(Plugin3()) # None result is ignored
res = pm.hook.hello(arg=3)
assert res == 2


def test_firstresult_returns_none(pm):
"""If None results are returned by underlying implementations ensure
the multi-call loop returns a None value.
"""
class Api(object):
@hookspec(firstresult=True)
def hello(self, arg):
"api hook 1"

pm.add_hookspecs(Api)

class Plugin1(object):
@hookimpl
def hello(self, arg):
return None

pm.register(Plugin1())
res = pm.hook.hello(arg=3)
assert res is None


def test_firstresult_no_plugin(pm):
"""If no implementations/plugins have been registered for a firstresult
hook the multi-call loop should return a None value.
"""
class Api(object):
@hookspec(firstresult=True)
def hello(self, arg):
"api hook 1"

pm.add_hookspecs(Api)
res = pm.hook.hello(arg=3)
assert res is None