bpo-44895: libregrtest: refleak check clears types later (GH-28113) · python/cpython@679cb47 · GitHub
Skip to content

Commit 679cb47

Browse files
bpo-44895: libregrtest: refleak check clears types later (GH-28113)
libregrtest now clears the type cache later to reduce the risk of false alarm when checking for reference leaks. Previously, the type cache was cleared too early and libregrtest raised a false alarm about reference leaks under very specific conditions. Move also support.gc_collect() outside clear/cleanup functions to make the garbage collection more explicit. Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
1 parent 863154c commit 679cb47

4 files changed

Lines changed: 20 additions & 14 deletions

File tree

Lib/test/libregrtest/refleak.py

Lines changed: 8 additions & 5 deletions

Lib/test/libregrtest/runtest.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,13 @@ def _runtest_inner2(ns: Namespace, test_name: str) -> bool:
297297
test_runner()
298298
refleak = False
299299
finally:
300-
cleanup_test_droppings(test_name, ns.verbose)
300+
# First kill any dangling references to open files etc.
301+
# This can also issue some ResourceWarnings which would otherwise get
302+
# triggered during the following test run, and possibly produce
303+
# failures.
304+
support.gc_collect()
301305

302-
support.gc_collect()
306+
cleanup_test_droppings(test_name, ns.verbose)
303307

304308
if gc.garbage:
305309
support.environment_altered = True
@@ -330,6 +334,7 @@ def _runtest_inner(
330334

331335
try:
332336
clear_caches()
337+
support.gc_collect()
333338

334339
with save_env(ns, test_name):
335340
refleak = _runtest_inner2(ns, test_name)
@@ -373,11 +378,6 @@ def _runtest_inner(
373378

374379

375380
def cleanup_test_droppings(test_name: str, verbose: int) -> None:
376-
# First kill any dangling references to open files etc.
377-
# This can also issue some ResourceWarnings which would otherwise get
378-
# triggered during the following test run, and possibly produce failures.
379-
support.gc_collect()
380-
381381
# Try to clean up junk commonly left behind. While tests shouldn't leave
382382
# any files or directories behind, when a test fails that can be tedious
383383
# for it to arrange. The consequences can be especially nasty on Windows,

Lib/test/libregrtest/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,5 +217,3 @@ def clear_caches():
217217
else:
218218
for f in typing._cleanups:
219219
f()
220-
221-
support.gc_collect()
Lines changed: 5 additions & 0 deletions

0 commit comments

Comments
 (0)