runner: collapse exception handling in SetupState.teardown_exact()

This is equivalent but simpler.
This commit is contained in:
Ran Benita 2021-01-01 13:06:50 +02:00
parent bb3d43c9a6
commit 0d4121d24b
1 changed files with 14 additions and 23 deletions

View File

@ -443,29 +443,20 @@ class SetupState:
while self.stack: while self.stack:
if self.stack == needed_collectors[: len(self.stack)]: if self.stack == needed_collectors[: len(self.stack)]:
break break
try:
colitem = self.stack.pop() colitem = self.stack.pop()
finalizers = self._finalizers.pop(colitem) finalizers = self._finalizers.pop(colitem)
finalizers.insert(0, colitem.teardown) finalizers.insert(0, colitem.teardown)
inner_exc = None
while finalizers: while finalizers:
fin = finalizers.pop() fin = finalizers.pop()
try: try:
fin() fin()
except TEST_OUTCOME as e:
# XXX Only first exception will be seen by user,
# ideally all should be reported.
if inner_exc is None:
inner_exc = e
for colitem in self._finalizers:
assert colitem in self.stack
if inner_exc:
raise inner_exc
except TEST_OUTCOME as e: except TEST_OUTCOME as e:
# XXX Only first exception will be seen by user, # XXX Only first exception will be seen by user,
# ideally all should be reported. # ideally all should be reported.
if exc is None: if exc is None:
exc = e exc = e
for colitem in self._finalizers:
assert colitem in self.stack
if exc: if exc:
raise exc raise exc
if nextitem is None: if nextitem is None: