summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2021-01-01 12:51:33 +0200
committerRan Benita <ran@unusedvar.com>2021-01-24 14:08:39 +0200
commitd1fcd425a3da18ecec35a6028093ebff830edd46 (patch)
treebc44c30704dc0307c7d0dd03849a44018049afe7 /src
parent2b14edb108f32c49c15b5e0c0ef4d27880b09e0f (diff)
downloadpytest-d1fcd425a3da18ecec35a6028093ebff830edd46.tar.gz
runner: inline SetupState._pop_and_teardown()
This will enable a simplification in the next commit.
Diffstat (limited to 'src')
-rw-r--r--src/_pytest/runner.py37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py
index 525aafc76..8102a6019 100644
--- a/src/_pytest/runner.py
+++ b/src/_pytest/runner.py
@@ -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.