From 94fe70d547a19e9d148aeaf55ee8f8b253c566b3 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 17 Jun 2024 14:11:12 -0400 Subject: [PATCH] Add filtering of the test context Python interpreter (#4364) Does not handle tests with multiple Python versions yet, working on that separately because the change is more invasive --- crates/uv/tests/common/mod.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/uv/tests/common/mod.rs b/crates/uv/tests/common/mod.rs index 54b444633..51aedba9e 100644 --- a/crates/uv/tests/common/mod.rs +++ b/crates/uv/tests/common/mod.rs @@ -70,7 +70,8 @@ impl TestContext { pub fn new(python_version: &str) -> Self { let temp_dir = assert_fs::TempDir::new().expect("Failed to create temp dir"); let cache_dir = assert_fs::TempDir::new().expect("Failed to create cache dir"); - let venv = create_venv(&temp_dir, &cache_dir, python_version); + let python = get_toolchain(python_version); + let venv = create_venv_from_executable(&temp_dir, &cache_dir, &python); // The workspace root directory is not available without walking up the tree // https://github.com/rust-lang/cargo/issues/3946 @@ -87,6 +88,11 @@ impl TestContext { PythonVersion::from_str(python_version).expect("Tests must use valid Python versions"); let mut filters = Vec::new(); + filters.extend( + Self::path_patterns(python) + .into_iter() + .map(|pattern| (format!("{pattern}python.*"), "[PYTHON]".to_string())), + ); filters.extend( Self::path_patterns(&cache_dir) .into_iter() @@ -534,14 +540,25 @@ pub fn get_toolchain(python: &str) -> PathBuf { } /// Create a virtual environment named `.venv` in a temporary directory with the given -/// Python version. Expected format for `python` is "". +/// Python version. pub fn create_venv>( temp_dir: &Parent, cache_dir: &assert_fs::TempDir, python: &str, ) -> PathBuf { let python = get_toolchain(python); + create_venv_from_executable(temp_dir, cache_dir, &python) +} +/// Create a virtual environment named `.venv` in a temporary directory with the given +/// Python executable. +pub fn create_venv_from_executable< + Parent: assert_fs::prelude::PathChild + AsRef, +>( + temp_dir: &Parent, + cache_dir: &assert_fs::TempDir, + python: &Path, +) -> PathBuf { let venv = temp_dir.child(".venv"); Command::new(get_bin()) .arg("venv")