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) while finalizers:
inner_exc = None fin = finalizers.pop()
while finalizers: try:
fin = finalizers.pop() fin()
try: except TEST_OUTCOME as e:
fin() # XXX Only first exception will be seen by user,
except TEST_OUTCOME as e: # ideally all should be reported.
# XXX Only first exception will be seen by user, if exc is None:
# ideally all should be reported. exc = e
if inner_exc is None: for colitem in self._finalizers:
inner_exc = e assert colitem in self.stack
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.
if exc is None:
exc = e
if exc: if exc:
raise exc raise exc
if nextitem is None: if nextitem is None: