From 8bbcb26ea6e798a10969570d24cd5e9c401feed7 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 28 Mar 2024 11:43:13 -0400 Subject: [PATCH] Call repo.close() instead of manually collecting The code this replaces in the `commit` pytest fixture seems not to be needed anymore, and could arguably be removed now with no further related changes. But whether it is needed depends on subtle and sometimes nondeterministic factors, and may also vary across Python versions. To be safe, this replaces it with a call to the Repo instance's close method, which is in effect more robust than what was being done before, as it calls clear_cache on the the Git object that the Repo object uses, does a gitdb/smmap collection, and on Windows calls gc.collect both before and after that collection. This may happen immediately anyway if the Repo object is not reachable from any cycle, since the reference count should go to zero after each of the deprecation warning tests (the fixture's lifetime is that of the test case), and Repo.close is called in Repo.__del__. But this makes it happen immediately even if there is a cycle. --- test/deprecation/test_various.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/deprecation/test_various.py b/test/deprecation/test_various.py index 71f9cf940..a82b989b7 100644 --- a/test/deprecation/test_various.py +++ b/test/deprecation/test_various.py @@ -4,7 +4,6 @@ """Tests of assorted deprecation warnings with no extra subtleties to check.""" import contextlib -import gc import warnings import pytest @@ -31,8 +30,7 @@ def commit(tmp_path): repo = Repo.init(tmp_path) repo.index.add(["a.txt"]) yield repo.index.commit("Initial commit") - del repo - gc.collect() + repo.close() @pytest.fixture