From 2eb1c725aa4dd3f07b7f053ab4ed6702e17476a8 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 26 Aug 2025 23:14:13 -0400 Subject: [PATCH] Fix failing virtualenv test on Windows (#15542) Closes https://github.com/astral-sh/uv/issues/15540. --- crates/uv/tests/it/venv.rs | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/crates/uv/tests/it/venv.rs b/crates/uv/tests/it/venv.rs index 3cd796f16..f5e542e9c 100644 --- a/crates/uv/tests/it/venv.rs +++ b/crates/uv/tests/it/venv.rs @@ -1594,7 +1594,9 @@ fn create_venv_nested_symlink_preservation() -> Result<()> { Ok(()) } +/// On Unix, creating a virtual environment in the current working directory should work. #[test] +#[cfg(unix)] fn create_venv_current_working_directory() { let context = TestContext::new_with_versions(&["3.12"]); @@ -1632,3 +1634,44 @@ fn create_venv_current_working_directory() { context.root.assert(predicates::path::is_dir()); } + +/// On Windows, creating a virtual environment in the current working directory should fail, +/// as you can't delete the current working directory. +#[test] +#[cfg(windows)] +fn create_venv_current_working_directory() { + let context = TestContext::new_with_versions(&["3.12"]); + + uv_snapshot!(context.filters(), context.venv() + .arg(context.venv.as_os_str()) + .arg("--python") + .arg("3.12"), @r" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Using CPython 3.12.[X] interpreter at: [PYTHON-3.12] + Creating virtual environment at: .venv + Activate with: source .venv/[BIN]/activate + " + ); + + uv_snapshot!(context.filters(), context.venv() + .arg(".") + .arg("--clear") + .arg("--python") + .arg("3.12") + .current_dir(&context.venv), @r" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + Using CPython 3.12.[X] interpreter at: [PYTHON-3.12] + Creating virtual environment at: . + error: Failed to create virtual environment + Caused by: failed to remove directory `[VENV]/`: The process cannot access the file because it is being used by another process. (os error 32) + " + ); +}