From 2616c8d6341032f6a9a977d7b46e1f311215c4dc Mon Sep 17 00:00:00 2001 From: Kshitiz_G Date: Fri, 11 Apr 2025 00:25:10 +0530 Subject: [PATCH] os.remove on Windows could fail if files are still in use Closes #535 --- cuda_core/tests/conftest.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cuda_core/tests/conftest.py b/cuda_core/tests/conftest.py index 8893724177..6face937b3 100644 --- a/cuda_core/tests/conftest.py +++ b/cuda_core/tests/conftest.py @@ -57,10 +57,19 @@ def deinit_cuda(): @pytest.fixture(scope="session", autouse=True) def clean_up_cffi_files(): - yield + # Clean up files from previous runs before the session starts files = glob.glob(os.path.join(os.getcwd(), "_cpu_obj*")) for f in files: try: # noqa: SIM105 os.remove(f) except FileNotFoundError: pass # noqa: SIM105 + except PermissionError: + # On Windows, removing a file in use raises PermissionError + # We can ignore this during setup, as the goal is just to + # clean up leftovers from *previous* runs. If a file is + # still in use now, it's likely from an ongoing process + # unrelated to the test session about to start. + pass + yield + # No cleanup needed after yield anymore