From 98b78d2c1558e4d2fef1d52ecfd30c15f181c38b Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Mon, 9 Mar 2026 13:27:16 -0400 Subject: [PATCH] Run `gc.collect()` twice in `test_rename` on Python 3.12 Recently, the conditional `gc.collect()` step for Python >= 3.12 in `TestSubmodule.test_rename` is often insufficient. This has mainly been seen in #2248. For example: https://github.com/gitpython-developers/GitPython/actions/runs/22864869684/job/66331124651?pr=2106#step:12:620 In principle, there can be situations with finalizers where a cycle is only collectable due to finalization that happened due to a previous collection. Therefore, there is occasionally a benefit to collecting twice. This does that, in the hope that it will help. --- test/test_submodule.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_submodule.py b/test/test_submodule.py index 2bf0940c9..47647f2a1 100644 --- a/test/test_submodule.py +++ b/test/test_submodule.py @@ -1011,6 +1011,7 @@ def test_rename(self, rwdir): # garbage collector detailed in https://github.com/python/cpython/issues/97922.) if sys.platform == "win32" and sys.version_info >= (3, 12): gc.collect() + gc.collect() # Some finalizer scenarios need two collections, at least in theory. new_path = "renamed/myname" assert sm.move(new_path).name == new_path