nose,fixtures: use the public item API for adding finalizers

This commit is contained in:
Ran Benita 2021-01-14 16:51:18 +02:00
parent 42d5545f42
commit addbd3161e
2 changed files with 4 additions and 8 deletions

View File

@ -543,10 +543,8 @@ class FixtureRequest:
self._addfinalizer(finalizer, scope=self.scope)
def _addfinalizer(self, finalizer: Callable[[], object], scope) -> None:
colitem = self._getscopeitem(scope)
self._pyfuncitem.session._setupstate.addfinalizer(
finalizer=finalizer, colitem=colitem
)
item = self._getscopeitem(scope)
item.addfinalizer(finalizer)
def applymarker(self, marker: Union[str, MarkDecorator]) -> None:
"""Apply a marker to a single test function invocation.
@ -694,9 +692,7 @@ class FixtureRequest:
self, fixturedef: "FixtureDef[object]", subrequest: "SubRequest"
) -> None:
# If fixture function failed it might have registered finalizers.
self.session._setupstate.addfinalizer(
functools.partial(fixturedef.finish, request=subrequest), subrequest.node
)
subrequest.node.addfinalizer(lambda: fixturedef.finish(request=subrequest))
def _check_scope(
self,

View File

@ -13,7 +13,7 @@ def pytest_runtest_setup(item) -> None:
# Call module level setup if there is no object level one.
call_optional(item.parent.obj, "setup")
# XXX This implies we only call teardown when setup worked.
item.session._setupstate.addfinalizer((lambda: teardown_nose(item)), item)
item.addfinalizer(lambda: teardown_nose(item))
def teardown_nose(item) -> None: