From a8f109ca1704827b017349d6d97f8a0a3229d9a8 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 27 Mar 2024 20:04:25 -0400 Subject: [PATCH] Fix exception in Popen.__del__ in test on Windows The newly introduced test would pass, but show: Exception ignored in: Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\subprocess.py", line 1130, in __del__ self._internal_poll(_deadstate=_maxsize) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.752.0_x64__qbz5n2kfra8p0\Lib\subprocess.py", line 1575, in _internal_poll if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ OSError: [WinError 6] The handle is invalid This was due to how, at least for now, the deprecation warning tests are not using GitPython's normal fixtures, which help clean things up on Windows. This adds a small amount of ad-hoc cleanup. It also moves the acquisition of the Diff object into a pytest fixture, which can be reused for the immediately forthcoming test that the preferred property does not warn. --- test/deprecation/test_various.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/deprecation/test_various.py b/test/deprecation/test_various.py index 9f948bc48..056e0ac0d 100644 --- a/test/deprecation/test_various.py +++ b/test/deprecation/test_various.py @@ -3,18 +3,27 @@ """Tests of assorted deprecation warnings with no extra subtleties to check.""" -from git.diff import NULL_TREE -from git.repo import Repo +import gc import pytest +from git.diff import NULL_TREE +from git.repo import Repo + -def test_diff_renamed_warns(tmp_path): +@pytest.fixture +def single_diff(tmp_path): + """Fixture to supply a single-file diff.""" (tmp_path / "a.txt").write_text("hello\n", encoding="utf-8") repo = Repo.init(tmp_path) repo.index.add(["a.txt"]) commit = repo.index.commit("Initial commit") (diff,) = commit.diff(NULL_TREE) # Exactly one file in the diff. + yield diff + del repo, commit, diff + gc.collect() + +def test_diff_renamed_warns(single_diff): with pytest.deprecated_call(): - diff.renamed + single_diff.renamed