MCPcopy
hub / github.com/pytest-dev/pytest / test_request_addfinalizer

Method test_request_addfinalizer

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

Source from the content-addressed store, hash-verified

1018 assert "request" in item.funcargs
1019
1020 def test_request_addfinalizer(self, pytester: Pytester) -> None:
1021 item = pytester.getitem(
1022 """
1023 import pytest
1024 teardownlist = []
1025 @pytest.fixture
1026 def something(request):
1027 request.addfinalizer(lambda: teardownlist.append(1))
1028 def test_func(something): pass
1029 """
1030 )
1031 assert isinstance(item, Function)
1032 item.session._setupstate.setup(item)
1033 item._request._fillfixtures()
1034 # successively check finalization calls
1035 parent = item.getparent(pytest.Module)
1036 assert parent is not None
1037 teardownlist = parent.obj.teardownlist
1038 ss = item.session._setupstate
1039 assert not teardownlist
1040 ss.teardown_exact(None)
1041 print(ss.stack)
1042 assert teardownlist == [1]
1043
1044 def test_request_addfinalizer_failing_setup(self, pytester: Pytester) -> None:
1045 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