runner: ensure item.teardown() is called even if a finalizer raised

If one finalizer fails, all of the subsequent finalizers still run, so
the `teardown()` method should behave the same.
This commit is contained in:
Ran Benita 2021-01-01 13:10:43 +02:00
parent 14d71b2c22
commit bb3d43c9a6
1 changed files with 3 additions and 3 deletions

View File

@ -446,6 +446,7 @@ class SetupState:
try:
colitem = self.stack.pop()
finalizers = self._finalizers.pop(colitem)
finalizers.insert(0, colitem.teardown)
inner_exc = None
while finalizers:
fin = finalizers.pop()
@ -456,11 +457,10 @@ class SetupState:
# ideally all should be reported.
if inner_exc is None:
inner_exc = e
if inner_exc:
raise inner_exc
colitem.teardown()
for colitem in self._finalizers:
assert colitem in self.stack
if inner_exc:
raise inner_exc
except TEST_OUTCOME as e:
# XXX Only first exception will be seen by user,
# ideally all should be reported.