Fix isolation of recursion test (#11481)

Closes https://github.com/astral-sh/uv/issues/11471
This commit is contained in:
Zanie Blue 2025-02-13 10:59:51 -06:00 committed by GitHub
parent a4bd73f922
commit bccd1dc973
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 40 deletions

View file

@ -503,7 +503,7 @@ impl TestContext {
/// Create a uv command for testing.
pub fn command(&self) -> Command {
let mut command = self.new_command();
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -535,7 +535,18 @@ impl TestContext {
/// * Hide other Pythons with `UV_PYTHON_INSTALL_DIR` and installed interpreters with
/// `UV_TEST_PYTHON_PATH` and an active venv (if applicable) by removing `VIRTUAL_ENV`.
/// * Increase the stack size to avoid stack overflows on windows due to large async functions.
pub fn add_shared_args(&self, command: &mut Command, activate_venv: bool) {
pub fn add_shared_options(&self, command: &mut Command, activate_venv: bool) {
self.add_shared_args(command);
self.add_shared_env(command, activate_venv);
}
/// Only the arguments of [`TestContext::add_shared_options`].
pub fn add_shared_args(&self, command: &mut Command) {
command.arg("--cache-dir").arg(self.cache_dir.path());
}
/// Only the environment variables of [`TestContext::add_shared_options`].
pub fn add_shared_env(&self, command: &mut Command, activate_venv: bool) {
// Push the test context bin to the front of the PATH
let path = env::join_paths(std::iter::once(self.bin_dir.to_path_buf()).chain(
env::split_paths(&env::var(EnvVars::PATH).unwrap_or_default()),
@ -543,8 +554,6 @@ impl TestContext {
.unwrap();
command
.arg("--cache-dir")
.arg(self.cache_dir.path())
// When running the tests in a venv, ignore that venv, otherwise we'll capture warnings.
.env_remove(EnvVars::VIRTUAL_ENV)
.env(EnvVars::UV_NO_WRAP, "1")
@ -580,7 +589,7 @@ impl TestContext {
pub fn pip_compile(&self) -> Command {
let mut command = self.new_command();
command.arg("pip").arg("compile");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -588,14 +597,14 @@ impl TestContext {
pub fn pip_sync(&self) -> Command {
let mut command = self.new_command();
command.arg("pip").arg("sync");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
pub fn pip_show(&self) -> Command {
let mut command = self.new_command();
command.arg("pip").arg("show");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -603,7 +612,7 @@ impl TestContext {
pub fn pip_freeze(&self) -> Command {
let mut command = self.new_command();
command.arg("pip").arg("freeze");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -611,14 +620,14 @@ impl TestContext {
pub fn pip_check(&self) -> Command {
let mut command = self.new_command();
command.arg("pip").arg("check");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
pub fn pip_list(&self) -> Command {
let mut command = self.new_command();
command.arg("pip").arg("list");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -626,7 +635,7 @@ impl TestContext {
pub fn venv(&self) -> Command {
let mut command = self.new_command();
command.arg("venv");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -634,7 +643,7 @@ impl TestContext {
pub fn pip_install(&self) -> Command {
let mut command = self.new_command();
command.arg("pip").arg("install");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -642,7 +651,7 @@ impl TestContext {
pub fn pip_uninstall(&self) -> Command {
let mut command = self.new_command();
command.arg("pip").arg("uninstall");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -650,7 +659,7 @@ impl TestContext {
pub fn pip_tree(&self) -> Command {
let mut command = self.new_command();
command.arg("pip").arg("tree");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -668,7 +677,7 @@ impl TestContext {
pub fn init(&self) -> Command {
let mut command = self.new_command();
command.arg("init");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -676,7 +685,7 @@ impl TestContext {
pub fn sync(&self) -> Command {
let mut command = self.new_command();
command.arg("sync");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -684,7 +693,7 @@ impl TestContext {
pub fn lock(&self) -> Command {
let mut command = self.new_command();
command.arg("lock");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -692,7 +701,7 @@ impl TestContext {
pub fn export(&self) -> Command {
let mut command = self.new_command();
command.arg("export");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -700,7 +709,7 @@ impl TestContext {
pub fn build(&self) -> Command {
let mut command = self.new_command();
command.arg("build");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -720,14 +729,14 @@ impl TestContext {
.env(EnvVars::UV_PREVIEW, "1")
.env(EnvVars::UV_PYTHON_INSTALL_DIR, "")
.current_dir(&self.temp_dir);
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
/// Create a `uv python install` command with options shared across scenarios.
pub fn python_install(&self) -> Command {
let mut command = self.new_command();
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
.arg("python")
.arg("install")
@ -738,7 +747,7 @@ impl TestContext {
/// Create a `uv python uninstall` command with options shared across scenarios.
pub fn python_uninstall(&self) -> Command {
let mut command = self.new_command();
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
.arg("python")
.arg("uninstall")
@ -750,7 +759,7 @@ impl TestContext {
pub fn python_pin(&self) -> Command {
let mut command = self.new_command();
command.arg("python").arg("pin");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -758,7 +767,7 @@ impl TestContext {
pub fn python_dir(&self) -> Command {
let mut command = self.new_command();
command.arg("python").arg("dir");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -766,7 +775,7 @@ impl TestContext {
pub fn run(&self) -> Command {
let mut command = self.new_command();
command.arg("run").env(EnvVars::UV_SHOW_RESOLUTION, "1");
self.add_shared_args(&mut command, true);
self.add_shared_options(&mut command, true);
command
}
@ -777,7 +786,7 @@ impl TestContext {
.arg("tool")
.arg("run")
.env(EnvVars::UV_SHOW_RESOLUTION, "1");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -785,7 +794,7 @@ impl TestContext {
pub fn tool_upgrade(&self) -> Command {
let mut command = self.new_command();
command.arg("tool").arg("upgrade");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -793,7 +802,7 @@ impl TestContext {
pub fn tool_install(&self) -> Command {
let mut command = self.new_command();
command.arg("tool").arg("install");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -801,7 +810,7 @@ impl TestContext {
pub fn tool_list(&self) -> Command {
let mut command = self.new_command();
command.arg("tool").arg("list");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -809,7 +818,7 @@ impl TestContext {
pub fn tool_dir(&self) -> Command {
let mut command = self.new_command();
command.arg("tool").arg("dir");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -817,7 +826,7 @@ impl TestContext {
pub fn tool_uninstall(&self) -> Command {
let mut command = self.new_command();
command.arg("tool").arg("uninstall");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -825,7 +834,7 @@ impl TestContext {
pub fn add(&self) -> Command {
let mut command = self.new_command();
command.arg("add");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -833,7 +842,7 @@ impl TestContext {
pub fn remove(&self) -> Command {
let mut command = self.new_command();
command.arg("remove");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -841,7 +850,7 @@ impl TestContext {
pub fn tree(&self) -> Command {
let mut command = self.new_command();
command.arg("tree");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -849,7 +858,7 @@ impl TestContext {
pub fn clean(&self) -> Command {
let mut command = self.new_command();
command.arg("cache").arg("clean");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -857,7 +866,7 @@ impl TestContext {
pub fn prune(&self) -> Command {
let mut command = self.new_command();
command.arg("cache").arg("prune");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}
@ -867,7 +876,7 @@ impl TestContext {
pub fn build_backend(&self) -> Command {
let mut command = self.new_command();
command.arg("build-backend");
self.add_shared_args(&mut command, false);
self.add_shared_options(&mut command, false);
command
}

View file

@ -33,7 +33,7 @@ fn command(context: &TestContext, python_versions: &[&str]) -> Command {
.arg(packse_index_url())
.arg("--find-links")
.arg(build_vendor_links_url());
context.add_shared_args(&mut command, true);
context.add_shared_options(&mut command, true);
command.env_remove(EnvVars::UV_EXCLUDE_NEWER);
command.env(EnvVars::UV_TEST_PYTHON_PATH, python_path);

View file

@ -50,7 +50,7 @@ fn command(context: &TestContext) -> Command {
.arg(packse_index_url())
.arg("--find-links")
.arg(build_vendor_links_url());
context.add_shared_args(&mut command, true);
context.add_shared_options(&mut command, true);
command.env_remove(EnvVars::UV_EXCLUDE_NEWER);
command
}

View file

@ -4218,11 +4218,12 @@ fn detect_infinite_recursion() -> Result<()> {
#!{uv} run
print("Hello, world!")
"#, uv = get_bin().display()})?;
"#, uv = get_bin().display() })?;
fs_err::set_permissions(test_script.path(), PermissionsExt::from_mode(0o0744))?;
let mut cmd = std::process::Command::new(test_script.as_os_str());
context.add_shared_env(&mut cmd, false);
// Set the max recursion depth to a lower amount to speed up testing.
cmd.env("UV_RUN_MAX_RECURSION_DEPTH", "5");