From 01d5d45a4b9e8044b6f624c7449cea2b713bf948 Mon Sep 17 00:00:00 2001 From: Ben Mares Date: Wed, 24 Jul 2024 09:17:12 +0200 Subject: [PATCH] Fix for Windows cache directory --- tests/test_pip_repositories.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_pip_repositories.py b/tests/test_pip_repositories.py index f8fe588d..888a6288 100644 --- a/tests/test_pip_repositories.py +++ b/tests/test_pip_repositories.py @@ -142,8 +142,7 @@ def test_it_uses_pip_repositories_with_env_var_substitution( monkeypatch.chdir(directory) environment_file = directory / "environment.yaml" assert environment_file.exists(), list(directory.iterdir()) - assert DEFAULT_CACHE_DIR.name == "pypoetry-conda-lock" - shutil.rmtree(DEFAULT_CACHE_DIR, ignore_errors=True) + clear_poetry_cache() # WHEN I create the lockfile run_lock([directory / "environment.yaml"], conda_exe=conda_exe) @@ -176,3 +175,16 @@ def test_it_uses_pip_repositories_with_env_var_substitution( "Password environment variable was not respected, See full lock-file:\n" + lockfile_content ) + + +def clear_poetry_cache() -> None: + # We are going to rmtree the cache directory. Let's be extra careful to make + # sure we only delete a directory named "pypoetry-conda-lock" or one of its + # subdirectories. + to_delete = DEFAULT_CACHE_DIR.resolve() + assert to_delete.name == "pypoetry-conda-lock" or ( + to_delete.parent.name == "pypoetry-conda-lock" and to_delete.name == "Cache" + ) + # Do another independent check that triggers even if we're in optimized mode + if "pypoetry-conda-lock" in to_delete.parts: + shutil.rmtree(DEFAULT_CACHE_DIR, ignore_errors=True)