runner: reorder SetupState method to make more sense
The setup stuff happens before the teardown stuff, so put it first so that reading the code from top to bottom makes more sense.
This commit is contained in:
parent
f7b0b1dd1f
commit
410622f719
|
@ -409,6 +409,26 @@ class SetupState:
|
||||||
self.stack: List[Node] = []
|
self.stack: List[Node] = []
|
||||||
self._finalizers: Dict[Node, List[Callable[[], object]]] = {}
|
self._finalizers: Dict[Node, List[Callable[[], object]]] = {}
|
||||||
|
|
||||||
|
_prepare_exc_key = StoreKey[Union[OutcomeException, Exception]]()
|
||||||
|
|
||||||
|
def prepare(self, colitem: Item) -> None:
|
||||||
|
"""Setup objects along the collector chain to the test-method."""
|
||||||
|
|
||||||
|
# Check if the last collection node has raised an error.
|
||||||
|
for col in self.stack:
|
||||||
|
prepare_exc = col._store.get(self._prepare_exc_key, None)
|
||||||
|
if prepare_exc:
|
||||||
|
raise prepare_exc
|
||||||
|
|
||||||
|
needed_collectors = colitem.listchain()
|
||||||
|
for col in needed_collectors[len(self.stack) :]:
|
||||||
|
self.stack.append(col)
|
||||||
|
try:
|
||||||
|
col.setup()
|
||||||
|
except TEST_OUTCOME as e:
|
||||||
|
col._store[self._prepare_exc_key] = e
|
||||||
|
raise e
|
||||||
|
|
||||||
def addfinalizer(self, finalizer: Callable[[], object], colitem: Node) -> None:
|
def addfinalizer(self, finalizer: Callable[[], object], colitem: Node) -> None:
|
||||||
"""Attach a finalizer to the given colitem."""
|
"""Attach a finalizer to the given colitem."""
|
||||||
assert colitem and not isinstance(colitem, tuple)
|
assert colitem and not isinstance(colitem, tuple)
|
||||||
|
@ -441,13 +461,6 @@ class SetupState:
|
||||||
for colitem in self._finalizers:
|
for colitem in self._finalizers:
|
||||||
assert colitem in self.stack
|
assert colitem in self.stack
|
||||||
|
|
||||||
def teardown_all(self) -> None:
|
|
||||||
while self.stack:
|
|
||||||
self._pop_and_teardown()
|
|
||||||
for key in list(self._finalizers):
|
|
||||||
self._teardown_with_finalization(key)
|
|
||||||
assert not self._finalizers
|
|
||||||
|
|
||||||
def teardown_exact(self, item: Item, nextitem: Optional[Item]) -> None:
|
def teardown_exact(self, item: Item, nextitem: Optional[Item]) -> None:
|
||||||
needed_collectors = nextitem and nextitem.listchain() or []
|
needed_collectors = nextitem and nextitem.listchain() or []
|
||||||
self._teardown_towards(needed_collectors)
|
self._teardown_towards(needed_collectors)
|
||||||
|
@ -467,25 +480,12 @@ class SetupState:
|
||||||
if exc:
|
if exc:
|
||||||
raise exc
|
raise exc
|
||||||
|
|
||||||
_prepare_exc_key = StoreKey[Union[OutcomeException, Exception]]()
|
def teardown_all(self) -> None:
|
||||||
|
while self.stack:
|
||||||
def prepare(self, colitem: Item) -> None:
|
self._pop_and_teardown()
|
||||||
"""Setup objects along the collector chain to the test-method."""
|
for key in list(self._finalizers):
|
||||||
|
self._teardown_with_finalization(key)
|
||||||
# Check if the last collection node has raised an error.
|
assert not self._finalizers
|
||||||
for col in self.stack:
|
|
||||||
prepare_exc = col._store.get(self._prepare_exc_key, None)
|
|
||||||
if prepare_exc:
|
|
||||||
raise prepare_exc
|
|
||||||
|
|
||||||
needed_collectors = colitem.listchain()
|
|
||||||
for col in needed_collectors[len(self.stack) :]:
|
|
||||||
self.stack.append(col)
|
|
||||||
try:
|
|
||||||
col.setup()
|
|
||||||
except TEST_OUTCOME as e:
|
|
||||||
col._store[self._prepare_exc_key] = e
|
|
||||||
raise e
|
|
||||||
|
|
||||||
|
|
||||||
def collect_one_node(collector: Collector) -> CollectReport:
|
def collect_one_node(collector: Collector) -> CollectReport:
|
||||||
|
|
Loading…
Reference in New Issue