Isolate virtual environment tests from developer toolchains (#4342)

Otherwise, when testing `uv venv --preview` the default toolchain
directory will leak into the test.

I believe I've made a similar change for the standard `TestContext` in
another commit somewhere in my stack, if not I'll add it after.
This commit is contained in:
Zanie Blue 2024-06-17 06:40:11 -04:00 committed by GitHub
parent 3a55c17ef1
commit 52bb9a694c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,7 @@ struct VenvTestContext {
cache_dir: assert_fs::TempDir, cache_dir: assert_fs::TempDir,
temp_dir: assert_fs::TempDir, temp_dir: assert_fs::TempDir,
venv: ChildPath, venv: ChildPath,
toolchain_dir: ChildPath,
python_path: OsString, python_path: OsString,
python_versions: Vec<PythonVersion>, python_versions: Vec<PythonVersion>,
} }
@ -29,6 +30,9 @@ impl VenvTestContext {
let python_path = python_path_with_versions(&temp_dir, python_versions) let python_path = python_path_with_versions(&temp_dir, python_versions)
.expect("Failed to create Python test path"); .expect("Failed to create Python test path");
let toolchain_dir = temp_dir.child("toolchains");
toolchain_dir.create_dir_all().unwrap();
// Canonicalize the virtual environment path for consistent snapshots across platforms // Canonicalize the virtual environment path for consistent snapshots across platforms
let venv = ChildPath::new(temp_dir.canonicalize().unwrap().join(".venv")); let venv = ChildPath::new(temp_dir.canonicalize().unwrap().join(".venv"));
@ -41,6 +45,7 @@ impl VenvTestContext {
Self { Self {
cache_dir: assert_fs::TempDir::new().unwrap(), cache_dir: assert_fs::TempDir::new().unwrap(),
temp_dir, temp_dir,
toolchain_dir,
venv, venv,
python_path, python_path,
python_versions, python_versions,
@ -55,6 +60,7 @@ impl VenvTestContext {
.arg(self.cache_dir.path()) .arg(self.cache_dir.path())
.arg("--exclude-newer") .arg("--exclude-newer")
.arg(EXCLUDE_NEWER) .arg(EXCLUDE_NEWER)
.env("UV_TOOLCHAIN_DIR", self.toolchain_dir.as_os_str())
.env("UV_TEST_PYTHON_PATH", self.python_path.clone()) .env("UV_TEST_PYTHON_PATH", self.python_path.clone())
.env("UV_NO_WRAP", "1") .env("UV_NO_WRAP", "1")
.env("UV_STACK_SIZE", (2 * 1024 * 1024).to_string()) .env("UV_STACK_SIZE", (2 * 1024 * 1024).to_string())