Skip to content

Commit

Permalink
Handle exceptions in hookwrapper post stage (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnikulin committed Jun 5, 2020
1 parent d59879e commit 36961c8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/pluggy/callers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def _multicall(hook_impls, caller_kwargs, firstresult=False):
next(gen) # first yield
teardowns.append(gen)
except StopIteration:
gen.close()
_raise_wrapfail(gen, "did not yield")
else:
res = hook_impl.function(*args)
Expand All @@ -127,9 +128,17 @@ def _multicall(hook_impls, caller_kwargs, firstresult=False):
# run all wrapper post-yield blocks
for gen in reversed(teardowns):
try:
gen.send(outcome)
_raise_wrapfail(gen, "has second yield")
except StopIteration:
pass
try:
gen.send(outcome)
_raise_wrapfail(gen, "has second yield")
except StopIteration:
pass
finally:
# Exception is risen only if generator
# suppresses GeneratorExit exception and yield
# so _raise_wrapfail above is necessary
gen.close()
except BaseException:
outcome = _Result(None, sys.exc_info())

return outcome.get_result()

0 comments on commit 36961c8

Please sign in to comment.