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

Function test_frame_leak_on_failing_test

testing/acceptance_test.py:1214–1244  ·  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

1212
1213
1214def test_frame_leak_on_failing_test(pytester: Pytester) -> None:
1215 """Pytest would leak garbage referencing the frames of tests that failed
1216 that could never be reclaimed (#2798).
1217
1218 Unfortunately it was not possible to remove the actual circles because most of them
1219 are made of traceback objects which cannot be weakly referenced. Those objects at least
1220 can be eventually claimed by the garbage collector.
1221 """
1222 pytester.makepyfile(
1223 """
1224 import gc
1225 import weakref
1226
1227 class Obj:
1228 pass
1229
1230 ref = None
1231
1232 def test1():
1233 obj = Obj()
1234 global ref
1235 ref = weakref.ref(obj)
1236 assert 0
1237
1238 def test2():
1239 gc.collect()
1240 assert ref() is None
1241 """
1242 )
1243 result = pytester.runpytest_subprocess()
1244 result.stdout.fnmatch_lines(["*1 failed, 1 passed in*"])
1245
1246
1247def 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…