runner: inline SetupState._pop_and_teardown()

This will enable a simplification in the next commit.
This commit is contained in:
Ran Benita 2021-01-01 12:51:33 +02:00
parent 2b14edb108
commit d1fcd425a3
2 changed files with 18 additions and 21 deletions

View File

@ -436,25 +436,6 @@ class SetupState:
# assert colitem in self.stack # some unit tests don't setup stack :/
self._finalizers.setdefault(colitem, []).append(finalizer)
def _pop_and_teardown(self) -> None:
colitem = self.stack.pop()
finalizers = self._finalizers.pop(colitem, None)
exc = None
while finalizers:
fin = finalizers.pop()
try:
fin()
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:
raise exc
colitem.teardown()
for colitem in self._finalizers:
assert colitem in self.stack
def teardown_exact(self, nextitem: Optional[Item]) -> None:
needed_collectors = nextitem and nextitem.listchain() or []
exc = None
@ -462,7 +443,23 @@ class SetupState:
if self.stack == needed_collectors[: len(self.stack)]:
break
try:
self._pop_and_teardown()
colitem = self.stack.pop()
finalizers = self._finalizers.pop(colitem, None)
inner_exc = None
while finalizers:
fin = finalizers.pop()
try:
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
if inner_exc:
raise inner_exc
colitem.teardown()
for colitem in self._finalizers:
assert colitem in self.stack
except TEST_OUTCOME as e:
# XXX Only first exception will be seen by user,
# ideally all should be reported.

View File

@ -28,7 +28,7 @@ class TestSetupState:
ss.prepare(item)
ss.addfinalizer(values.pop, colitem=item)
assert values
ss._pop_and_teardown()
ss.teardown_exact(None)
assert not values
def test_teardown_exact_stack_empty(self, pytester: Pytester) -> None: