From f0c4865d3fd4a9c5acb1e139034fcb6afc6c0209 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 25 Nov 2024 16:05:25 -0600 Subject: [PATCH] Add test case for empty virtual environment directory (#9426) Test case for #9427 --- crates/uv/tests/it/sync.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/uv/tests/it/sync.rs b/crates/uv/tests/it/sync.rs index 985b7e0ef150..3c6014912a8f 100644 --- a/crates/uv/tests/it/sync.rs +++ b/crates/uv/tests/it/sync.rs @@ -2775,6 +2775,38 @@ fn sync_workspace_custom_environment_path() -> Result<()> { Ok(()) } +#[test] +fn sync_empty_virtual_environment() -> Result<()> { + let context = TestContext::new_with_versions(&["3.12"]); + + // Create an empty directory + context.temp_dir.child(".venv").create_dir_all()?; + + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" + [project] + name = "project" + version = "0.1.0" + requires-python = ">=3.12" + dependencies = ["iniconfig"] + "#, + )?; + + // Running `uv sync` should work + uv_snapshot!(context.filters(), context.sync(), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + Using CPython 3.12.[X] interpreter at: [PYTHON-3.12] + error: Project virtual environment directory `[VENV]/` cannot be used because it is not a compatible environment but cannot be recreated because it is not a virtual environment + "###); + + Ok(()) +} + /// Test for warnings when `VIRTUAL_ENV` is set but will not be respected. #[test] fn sync_legacy_non_project_warning() -> Result<()> {