Skip to content

Commit

Permalink
uv/tests: filter out link mode warning in one test
Browse files Browse the repository at this point in the history
In the `lock_redact_https` test specifically, it prompts a link mode
warning from `uv` on my system. Debugging seems to suggest it is
provoked by attempting to hardlink between `/tmp` and `~/.local`. Since
these are on different file systems for me (with `/tmp` being a
ramdisk), it provokes the warning, and this turn spoils the snapshot
when running tests locally.

This PR adds a test specific filter rule to fix this.
  • Loading branch information
BurntSushi committed Sep 4, 2024
1 parent e7c9a9c commit 5b643ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
15 changes: 15 additions & 0 deletions crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ impl TestContext {
}
self
}

/// Adds a filter that specifically ignores the link mode warning.
///
/// This occurs in some cases and can be used on an ad hoc basis to squash
/// the warning in the snapshots. This is useful because the warning does
/// not consistently appear. It is dependent on the environment. (For
/// example, sometimes it's dependent on whether `/tmp` and `~/.local` live
/// on the same file system.)
#[inline]
pub fn with_filtered_link_mode_warning(mut self) -> Self {
let pattern = "warning: Failed to hardlink files; .*\n.*\n.*\n";
self.filters.push((pattern.to_string(), String::new()));
self
}

/// Discover the path to the XDG state directory. We use this, rather than the OS-specific
/// temporary directory, because on macOS (and Windows on GitHub Actions), they involve
/// symlinks. (On macOS, the temporary directory is, like `/var/...`, which resolves to
Expand Down
13 changes: 12 additions & 1 deletion crates/uv/tests/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5834,7 +5834,18 @@ fn lock_dev_transitive() -> Result<()> {
/// Avoid persisting registry credentials in `uv.lock`.
#[test]
fn lock_redact_https() -> Result<()> {
let context = TestContext::new("3.12");
// This test in particular seems to prompt a link mode warning
// that occurs when hardlinking fails. In particular, in this test,
// uv tries to hardlink between `/tmp` and `~/.local`, which on my
// system fails because `/tmp` is a different file system (a ramdisk).
// So we filter this warning out so that our snapshot tests pass on
// systems where this warning pops up.
//
// This is caused by using `--no-cache` in some of the commands below,
// which in turns means we don't use the test context cache location.
// We should probably add a way to configure the `--no-cache` temporary
// directory location during testing.
let context = TestContext::new("3.12").with_filtered_link_mode_warning();

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
Expand Down

0 comments on commit 5b643ce

Please sign in to comment.