diff options
author | Ran Benita <ran@unusedvar.com> | 2020-12-30 17:20:19 +0200 |
---|---|---|
committer | Ran Benita <ran@unusedvar.com> | 2021-01-24 14:08:39 +0200 |
commit | f7b0b1dd1f6f2722da2cc1a908fdd2843cbdb111 (patch) | |
tree | a778503e23a7593085de89b28e814d03f1d1628e /src | |
parent | da70f61f67cc37209a5d97bca18303bdd7bccbc8 (diff) | |
download | pytest-f7b0b1dd1f6f2722da2cc1a908fdd2843cbdb111.tar.gz |
runner: use node's Store to keep private SetupState state instead of an attribute
This way it gets proper typing and decoupling.
Diffstat (limited to 'src')
-rw-r--r-- | src/_pytest/runner.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index a49879432..7087c6c59 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -33,8 +33,10 @@ from _pytest.nodes import Collector from _pytest.nodes import Item from _pytest.nodes import Node from _pytest.outcomes import Exit +from _pytest.outcomes import OutcomeException from _pytest.outcomes import Skipped from _pytest.outcomes import TEST_OUTCOME +from _pytest.store import StoreKey if TYPE_CHECKING: from typing_extensions import Literal @@ -465,14 +467,16 @@ class SetupState: if exc: raise exc + _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: - if hasattr(col, "_prepare_exc"): - exc = col._prepare_exc # type: ignore[attr-defined] - raise exc + 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) :]: @@ -480,7 +484,7 @@ class SetupState: try: col.setup() except TEST_OUTCOME as e: - col._prepare_exc = e # type: ignore[attr-defined] + col._store[self._prepare_exc_key] = e raise e |