diff --git a/.coveragerc b/.coveragerc index 1b1de1cd..f16624af 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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 diff --git a/src/pluggy/callers.py b/src/pluggy/callers.py index e7ea464b..3243dd8b 100644 --- a/src/pluggy/callers.py +++ b/src/pluggy/callers.py @@ -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: diff --git a/testing/test_multicall.py b/testing/test_multicall.py index eaf534a0..bfe4fa51 100644 --- a/testing/test_multicall.py +++ b/testing/test_multicall.py @@ -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"] @@ -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"]