Skip to content

Commit

Permalink
Handle exceptions in hookwrapper post stage (pytest-dev#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnikulin committed Feb 8, 2022
1 parent e042809 commit fbfb60c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pluggy/_callers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,18 @@ def _multicall(
for gen in reversed(teardowns):
try:
gen.send(outcome)
# Following is unreachable for a well behaved hook wrapper.
# Try to force finalizers otherwise postponed till GC action.
# Note: close() may raise if generator handles GeneratorExit.
gen.close()
_raise_wrapfail(gen, "has second yield")
except StopIteration:
# Regular code path: exited after single yield, close() is unnecessary.
pass
except BaseException:
# Any other exception: instead of yield, in response to close, extra yield.
cur_excinfo = sys.exc_info()
if cur_excinfo[0] is not None: # silence type checker
outcome._excinfo = cur_excinfo

return outcome.get_result()

0 comments on commit fbfb60c

Please sign in to comment.