nose,fixtures: use the public item API for adding finalizers
This commit is contained in:
parent
42d5545f42
commit
addbd3161e
|
@ -543,10 +543,8 @@ class FixtureRequest:
|
||||||
self._addfinalizer(finalizer, scope=self.scope)
|
self._addfinalizer(finalizer, scope=self.scope)
|
||||||
|
|
||||||
def _addfinalizer(self, finalizer: Callable[[], object], scope) -> None:
|
def _addfinalizer(self, finalizer: Callable[[], object], scope) -> None:
|
||||||
colitem = self._getscopeitem(scope)
|
item = self._getscopeitem(scope)
|
||||||
self._pyfuncitem.session._setupstate.addfinalizer(
|
item.addfinalizer(finalizer)
|
||||||
finalizer=finalizer, colitem=colitem
|
|
||||||
)
|
|
||||||
|
|
||||||
def applymarker(self, marker: Union[str, MarkDecorator]) -> None:
|
def applymarker(self, marker: Union[str, MarkDecorator]) -> None:
|
||||||
"""Apply a marker to a single test function invocation.
|
"""Apply a marker to a single test function invocation.
|
||||||
|
@ -694,9 +692,7 @@ class FixtureRequest:
|
||||||
self, fixturedef: "FixtureDef[object]", subrequest: "SubRequest"
|
self, fixturedef: "FixtureDef[object]", subrequest: "SubRequest"
|
||||||
) -> None:
|
) -> None:
|
||||||
# If fixture function failed it might have registered finalizers.
|
# If fixture function failed it might have registered finalizers.
|
||||||
self.session._setupstate.addfinalizer(
|
subrequest.node.addfinalizer(lambda: fixturedef.finish(request=subrequest))
|
||||||
functools.partial(fixturedef.finish, request=subrequest), subrequest.node
|
|
||||||
)
|
|
||||||
|
|
||||||
def _check_scope(
|
def _check_scope(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -13,7 +13,7 @@ def pytest_runtest_setup(item) -> None:
|
||||||
# Call module level setup if there is no object level one.
|
# Call module level setup if there is no object level one.
|
||||||
call_optional(item.parent.obj, "setup")
|
call_optional(item.parent.obj, "setup")
|
||||||
# XXX This implies we only call teardown when setup worked.
|
# 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:
|
def teardown_nose(item) -> None:
|
||||||
|
|
Loading…
Reference in New Issue