runner: express SetupState.teardown_all() in terms of teardown_exact() and remove it
Makes it easier to understand with fewer methods.
This commit is contained in:
parent
ceb4d6f6d5
commit
2b14edb108
|
@ -105,7 +105,7 @@ def pytest_sessionstart(session: "Session") -> None:
|
|||
|
||||
|
||||
def pytest_sessionfinish(session: "Session") -> None:
|
||||
session._setupstate.teardown_all()
|
||||
session._setupstate.teardown_exact(None)
|
||||
|
||||
|
||||
def pytest_runtest_protocol(item: Item, nextitem: Optional[Item]) -> bool:
|
||||
|
@ -177,7 +177,7 @@ def pytest_runtest_call(item: Item) -> None:
|
|||
|
||||
def pytest_runtest_teardown(item: Item, nextitem: Optional[Item]) -> None:
|
||||
_update_current_test_var(item, "teardown")
|
||||
item.session._setupstate.teardown_exact(item, nextitem)
|
||||
item.session._setupstate.teardown_exact(nextitem)
|
||||
_update_current_test_var(item, None)
|
||||
|
||||
|
||||
|
@ -455,7 +455,7 @@ class SetupState:
|
|||
for colitem in self._finalizers:
|
||||
assert colitem in self.stack
|
||||
|
||||
def teardown_exact(self, item: Item, nextitem: Optional[Item]) -> None:
|
||||
def teardown_exact(self, nextitem: Optional[Item]) -> None:
|
||||
needed_collectors = nextitem and nextitem.listchain() or []
|
||||
exc = None
|
||||
while self.stack:
|
||||
|
@ -470,10 +470,7 @@ class SetupState:
|
|||
exc = e
|
||||
if exc:
|
||||
raise exc
|
||||
|
||||
def teardown_all(self) -> None:
|
||||
while self.stack:
|
||||
self._pop_and_teardown()
|
||||
if nextitem is None:
|
||||
assert not self._finalizers
|
||||
|
||||
|
||||
|
|
|
@ -856,7 +856,7 @@ class TestRequestBasic:
|
|||
teardownlist = parent.obj.teardownlist
|
||||
ss = item.session._setupstate
|
||||
assert not teardownlist
|
||||
ss.teardown_exact(item, None)
|
||||
ss.teardown_exact(None)
|
||||
print(ss.stack)
|
||||
assert teardownlist == [1]
|
||||
|
||||
|
|
|
@ -34,9 +34,10 @@ class TestSetupState:
|
|||
def test_teardown_exact_stack_empty(self, pytester: Pytester) -> None:
|
||||
item = pytester.getitem("def test_func(): pass")
|
||||
ss = runner.SetupState()
|
||||
ss.teardown_exact(item, None)
|
||||
ss.teardown_exact(item, None)
|
||||
ss.teardown_exact(item, None)
|
||||
ss.prepare(item)
|
||||
ss.teardown_exact(None)
|
||||
ss.teardown_exact(None)
|
||||
ss.teardown_exact(None)
|
||||
|
||||
def test_setup_fails_and_failure_is_cached(self, pytester: Pytester) -> None:
|
||||
item = pytester.getitem(
|
||||
|
@ -69,7 +70,7 @@ class TestSetupState:
|
|||
ss.addfinalizer(fin2, item)
|
||||
ss.addfinalizer(fin3, item)
|
||||
with pytest.raises(Exception) as err:
|
||||
ss.teardown_exact(item, None)
|
||||
ss.teardown_exact(None)
|
||||
assert err.value.args == ("oops",)
|
||||
assert r == ["fin3", "fin1"]
|
||||
|
||||
|
@ -88,7 +89,7 @@ class TestSetupState:
|
|||
ss.addfinalizer(fin1, item)
|
||||
ss.addfinalizer(fin2, item)
|
||||
with pytest.raises(Exception) as err:
|
||||
ss.teardown_exact(item, None)
|
||||
ss.teardown_exact(None)
|
||||
assert err.value.args == ("oops2",)
|
||||
|
||||
def test_teardown_multiple_scopes_one_fails(self, pytester: Pytester) -> None:
|
||||
|
@ -106,7 +107,7 @@ class TestSetupState:
|
|||
ss.addfinalizer(fin_func, item)
|
||||
ss.prepare(item)
|
||||
with pytest.raises(Exception, match="oops1"):
|
||||
ss.teardown_exact(item, None)
|
||||
ss.teardown_exact(None)
|
||||
assert module_teardown
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue