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

Function test_frame_leak_on_failing_test

testing/acceptance_test.py:1108–1138  ·  view source on GitHub ↗

Pytest would leak garbage referencing the frames of tests that failed that could never be reclaimed (#2798). Unfortunately it was not possible to remove the actual circles because most of them are made of traceback objects which cannot be weakly referenced. Those objects at least ca

(pytester: Pytester)

Source from the content-addressed store, hash-verified

1106
1107
1108def test_frame_leak_on_failing_test(pytester: Pytester) -> None:
1109 """Pytest would leak garbage referencing the frames of tests that failed
1110 that could never be reclaimed (#2798).
1111
1112 Unfortunately it was not possible to remove the actual circles because most of them
1113 are made of traceback objects which cannot be weakly referenced. Those objects at least
1114 can be eventually claimed by the garbage collector.
1115 """
1116 pytester.makepyfile(
1117 """
1118 import gc
1119 import weakref
1120
1121 class Obj:
1122 pass
1123
1124 ref = None
1125
1126 def test1():
1127 obj = Obj()
1128 global ref
1129 ref = weakref.ref(obj)
1130 assert 0
1131
1132 def test2():
1133 gc.collect()
1134 assert ref() is None
1135 """
1136 )
1137 result = pytester.runpytest_subprocess()
1138 result.stdout.fnmatch_lines(["*1 failed, 1 passed in*"])
1139
1140
1141def test_fixture_mock_integration(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytest_subprocessMethod · 0.45

Tested by

no test coverage detected