Skip to content
Closed
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
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ source = pluggy/
*/lib/python*/site-packages/pluggy/
*/pypy*/site-packages/pluggy/
*\Lib\site-packages\pluggy\

[report]
skip_covered = True
show_missing = True
exclude_lines =
\#\s*pragma: no cover
^\s*raise NotImplementedError\b
^\s*return NotImplemented\b
6 changes: 5 additions & 1 deletion src/pluggy/callers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ def _multicall(hook_impls, caller_kwargs, firstresult=False):
if hook_impl.hookwrapper:
try:
gen = hook_impl.function(*args)
next(gen) # first yield
res = next(gen) # first yield
teardowns.append(gen)
if res is not None:
results.append(res)
if firstresult:
break
except StopIteration:
_raise_wrapfail(gen, "did not yield")
else:
Expand Down
20 changes: 19 additions & 1 deletion testing/test_multicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def m2():
out.append("m2 finish")

res = MC([m2, m1], {})
assert res == []
assert res == [1, 2]
assert out == ["m1 init", "m2 init", "m2 finish", "m1 finish"]


Expand Down Expand Up @@ -184,3 +184,21 @@ def m2():
with pytest.raises(exc):
MC([m2, m1], {})
assert out == ["m1 init", "m1 finish"]


def test_hookwrapper_firstresult():
out = []

@hookimpl(hookwrapper=True)
def m1():
out.append("m1 init")
yield "hookwrapper_result"
out.append("m1 finish")

@hookimpl
def m2():
raise NotImplementedError()

res = MC([m2, m1], {}, firstresult=True)
assert res == "hookwrapper_result"
assert out == ["m1 init", "m1 finish"]