From e8899fe7f98414afbc73c5ee80eb9466d8e0e6b5 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 16 Sep 2024 15:41:53 -0500 Subject: [PATCH] Add test case for Python pre-release versions from `VIRTUAL_ENV` (#7437) --- crates/uv-python/src/lib.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/crates/uv-python/src/lib.rs b/crates/uv-python/src/lib.rs index 82fe49bd8..68ea3c39d 100644 --- a/crates/uv-python/src/lib.rs +++ b/crates/uv-python/src/lib.rs @@ -964,7 +964,7 @@ mod tests { #[test] fn find_python_from_active_python() -> Result<()> { let context = TestContext::new()?; - let venv = context.tempdir.child(".venv"); + let venv = context.tempdir.child("some-venv"); TestContext::mock_venv(&venv, "3.12.0")?; let python = @@ -985,6 +985,31 @@ mod tests { Ok(()) } + #[test] + fn find_python_from_active_python_prerelease() -> Result<()> { + let mut context = TestContext::new()?; + context.add_python_versions(&["3.12.0"])?; + let venv = context.tempdir.child("some-venv"); + TestContext::mock_venv(&venv, "3.13.0rc1")?; + + let python = + context.run_with_vars(&[("VIRTUAL_ENV", Some(venv.as_os_str()))], || { + find_python_installation( + &PythonRequest::Any, + EnvironmentPreference::Any, + PythonPreference::OnlySystem, + &context.cache, + ) + })??; + assert_eq!( + python.interpreter().python_full_version().to_string(), + "3.13.0rc1", + "We should prefer the active environment" + ); + + Ok(()) + } + #[test] fn find_python_from_conda_prefix() -> Result<()> { let context = TestContext::new()?;