runner: inline a couple of SetupState methods

Code is clearer this way.
This commit is contained in:
Ran Benita 2020-12-30 17:36:42 +02:00
parent 5f4e55fb6d
commit ceb4d6f6d5
2 changed files with 4 additions and 8 deletions

View File

@ -438,9 +438,6 @@ class SetupState:
def _pop_and_teardown(self) -> None:
colitem = self.stack.pop()
self._teardown_with_finalization(colitem)
def _callfinalizers(self, colitem: Node) -> None:
finalizers = self._finalizers.pop(colitem, None)
exc = None
while finalizers:
@ -454,9 +451,6 @@ class SetupState:
exc = e
if exc:
raise exc
def _teardown_with_finalization(self, colitem: Node) -> None:
self._callfinalizers(colitem)
colitem.teardown()
for colitem in self._finalizers:
assert colitem in self.stack

View File

@ -64,11 +64,12 @@ class TestSetupState:
item = pytester.getitem("def test_func(): pass")
ss = runner.SetupState()
ss.prepare(item)
ss.addfinalizer(fin1, item)
ss.addfinalizer(fin2, item)
ss.addfinalizer(fin3, item)
with pytest.raises(Exception) as err:
ss._callfinalizers(item)
ss.teardown_exact(item, None)
assert err.value.args == ("oops",)
assert r == ["fin3", "fin1"]
@ -83,10 +84,11 @@ class TestSetupState:
item = pytester.getitem("def test_func(): pass")
ss = runner.SetupState()
ss.prepare(item)
ss.addfinalizer(fin1, item)
ss.addfinalizer(fin2, item)
with pytest.raises(Exception) as err:
ss._callfinalizers(item)
ss.teardown_exact(item, None)
assert err.value.args == ("oops2",)
def test_teardown_multiple_scopes_one_fails(self, pytester: Pytester) -> None: