MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_request_addfinalizer

Method test_request_addfinalizer

testing/python/fixtures.py:846–868  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

844 assert "request" in item.funcargs
845
846 def test_request_addfinalizer(self, pytester: Pytester) -> None:
847 item = pytester.getitem(
848 """
849 import pytest
850 teardownlist = []
851 @pytest.fixture
852 def something(request):
853 request.addfinalizer(lambda: teardownlist.append(1))
854 def test_func(something): pass
855 """
856 )
857 assert isinstance(item, Function)
858 item.session._setupstate.setup(item)
859 item._request._fillfixtures()
860 # successively check finalization calls
861 parent = item.getparent(pytest.Module)
862 assert parent is not None
863 teardownlist = parent.obj.teardownlist
864 ss = item.session._setupstate
865 assert not teardownlist
866 ss.teardown_exact(None)
867 print(ss.stack)
868 assert teardownlist == [1]
869
870 def test_request_addfinalizer_failing_setup(self, pytester: Pytester) -> None:
871 pytester.makepyfile(

Callers

nothing calls this directly

Calls 5

_fillfixturesMethod · 0.80
getparentMethod · 0.80
teardown_exactMethod · 0.80
getitemMethod · 0.45
setupMethod · 0.45

Tested by

no test coverage detected