From f42b68ccaa4a64b3f7ef1cfcff50b4f39b63ceb9 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 31 Jan 2021 12:14:06 +0200 Subject: runner: rename SetupState.prepare -> setup This is the usual terminology we use, and matches better with `teardown_exact()` and `pytest_runtest_setup()`. --- src/_pytest/fixtures.py | 2 +- src/_pytest/runner.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 269369642..40b482d04 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -372,7 +372,7 @@ def _fill_fixtures_impl(function: "Function") -> None: fi = fm.getfixtureinfo(function.parent, function.obj, None) function._fixtureinfo = fi request = function._request = FixtureRequest(function, _ispytest=True) - fm.session._setupstate.prepare(function) + fm.session._setupstate.setup(function) request._fillfixtures() # Prune out funcargs for jstests. newfuncargs = {} diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index 124cf531a..153b134fe 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -151,7 +151,7 @@ def show_test_item(item: Item) -> None: def pytest_runtest_setup(item: Item) -> None: _update_current_test_var(item, "setup") - item.session._setupstate.prepare(item) + item.session._setupstate.setup(item) def pytest_runtest_call(item: Item) -> None: @@ -417,7 +417,7 @@ class SetupState: [] - During the setup phase of item1, prepare(item1) is called. What it does + During the setup phase of item1, setup(item1) is called. What it does is: push session to stack, run session.setup() @@ -441,7 +441,7 @@ class SetupState: [session] - During the setup phase of item2, prepare(item2) is called. What it does + During the setup phase of item2, setup(item2) is called. What it does is: push mod2 to stack, run mod2.setup() @@ -477,16 +477,16 @@ class SetupState: ], ] = {} - def prepare(self, item: Item) -> None: + def setup(self, item: Item) -> None: """Setup objects along the collector chain to the item.""" needed_collectors = item.listchain() # If a collector fails its setup, fail its entire subtree of items. # The setup is not retried for each item - the same exception is used. - for col, (finalizers, prepare_exc) in self.stack.items(): + for col, (finalizers, exc) in self.stack.items(): assert col in needed_collectors, "previous item was not torn down properly" - if prepare_exc: - raise prepare_exc + if exc: + raise exc for col in needed_collectors[len(self.stack) :]: assert col not in self.stack @@ -494,9 +494,9 @@ class SetupState: self.stack[col] = ([col.teardown], None) try: col.setup() - except TEST_OUTCOME as e: - self.stack[col] = (self.stack[col][0], e) - raise e + except TEST_OUTCOME as exc: + self.stack[col] = (self.stack[col][0], exc) + raise exc def addfinalizer(self, finalizer: Callable[[], object], node: Node) -> None: """Attach a finalizer to the given node. @@ -520,7 +520,7 @@ class SetupState: while self.stack: if list(self.stack.keys()) == needed_collectors[: len(self.stack)]: break - node, (finalizers, prepare_exc) = self.stack.popitem() + node, (finalizers, _) = self.stack.popitem() while finalizers: fin = finalizers.pop() try: -- cgit v1.2.3