Skip to content

Commit 9305bad

Browse files
Fix show_settings tests not to be affected by system configs (#9992)
<!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Override XDG_CONFIG_DIRS in show_settings tests, in order to ensure that they don't pick system configuration, and therefore fail due to value mismatches. This specifically addresses test failures on Gentoo where a default `/etc/xdg/uv/uv.toml` is installed, and users are free to modify it. Prior to #9914, we used to set `XDG_CONFIG_DIRS` locally before running the test suite. However, since the test now wipes the environment, the problem can no longer be resolved downstream. ## Test Plan `cargo test` on a Gentoo system (with `/etc/xdg/uv/uv.toml` present). --------- Co-authored-by: Charlie Marsh <[email protected]>
1 parent dd760ee commit 9305bad

File tree

1 file changed

+45
-42
lines changed

1 file changed

+45
-42
lines changed

crates/uv/tests/it/show_settings.rs

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::path::Path;
12
use std::process::Command;
23

34
use assert_fs::prelude::*;
@@ -9,13 +10,15 @@ use crate::common::{uv_snapshot, TestContext};
910
///
1011
/// In particular, remove any user-defined environment variables and set any machine-specific
1112
/// environment variables to static values.
12-
fn add_shared_args(mut command: Command) -> Command {
13+
fn add_shared_args(mut command: Command, cwd: &Path) -> Command {
1314
command
1415
.env_clear()
1516
.env(EnvVars::UV_LINK_MODE, "clone")
1617
.env(EnvVars::UV_CONCURRENT_DOWNLOADS, "50")
1718
.env(EnvVars::UV_CONCURRENT_BUILDS, "16")
18-
.env(EnvVars::UV_CONCURRENT_INSTALLS, "8");
19+
.env(EnvVars::UV_CONCURRENT_INSTALLS, "8")
20+
// Set an explicit `XDG_CONFIG_DIRS` to avoid loading system configuration.
21+
.env(EnvVars::XDG_CONFIG_DIRS, cwd);
1922

2023
if cfg!(unix) {
2124
// Avoid locale issues in tests
@@ -53,7 +56,7 @@ fn resolve_uv_toml() -> anyhow::Result<()> {
5356
requirements_in.write_str("anyio>3.0.0")?;
5457

5558
// Resolution should use the lowest direct version, and generate hashes.
56-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
59+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
5760
.arg("--show-settings")
5861
.arg("requirements.in"), @r###"
5962
success: true
@@ -204,7 +207,7 @@ fn resolve_uv_toml() -> anyhow::Result<()> {
204207
);
205208

206209
// Resolution should use the highest version, and generate hashes.
207-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
210+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
208211
.arg("--show-settings")
209212
.arg("requirements.in")
210213
.arg("--resolution=highest"), @r###"
@@ -356,7 +359,7 @@ fn resolve_uv_toml() -> anyhow::Result<()> {
356359
);
357360

358361
// Resolution should use the highest version, and omit hashes.
359-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
362+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
360363
.arg("--show-settings")
361364
.arg("requirements.in")
362365
.arg("--resolution=highest")
@@ -543,7 +546,7 @@ fn resolve_pyproject_toml() -> anyhow::Result<()> {
543546
requirements_in.write_str("anyio>3.0.0")?;
544547

545548
// Resolution should use the lowest direct version, and generate hashes.
546-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
549+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
547550
.arg("--show-settings")
548551
.arg("requirements.in"), @r###"
549552
success: true
@@ -697,7 +700,7 @@ fn resolve_pyproject_toml() -> anyhow::Result<()> {
697700
fs_err::remove_file(config.path())?;
698701

699702
// Resolution should use the highest version, and omit hashes.
700-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
703+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
701704
.arg("--show-settings")
702705
.arg("requirements.in"), @r###"
703706
success: true
@@ -830,7 +833,7 @@ fn resolve_pyproject_toml() -> anyhow::Result<()> {
830833
"#})?;
831834

832835
// Resolution should use the lowest direct version, and generate hashes.
833-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
836+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
834837
.arg("--show-settings")
835838
.arg("requirements.in"), @r###"
836839
success: true
@@ -1007,7 +1010,7 @@ fn resolve_index_url() -> anyhow::Result<()> {
10071010
let requirements_in = context.temp_dir.child("requirements.in");
10081011
requirements_in.write_str("anyio>3.0.0")?;
10091012

1010-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
1013+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
10111014
.arg("--show-settings")
10121015
.arg("requirements.in"), @r###"
10131016
success: true
@@ -1188,7 +1191,7 @@ fn resolve_index_url() -> anyhow::Result<()> {
11881191

11891192
// Providing an additional index URL on the command-line should be merged with the
11901193
// configuration file.
1191-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
1194+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
11921195
.arg("--show-settings")
11931196
.arg("requirements.in")
11941197
.arg("--extra-index-url")
@@ -1427,7 +1430,7 @@ fn resolve_find_links() -> anyhow::Result<()> {
14271430
let requirements_in = context.temp_dir.child("requirements.in");
14281431
requirements_in.write_str("tqdm")?;
14291432

1430-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
1433+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
14311434
.arg("--show-settings")
14321435
.arg("requirements.in"), @r###"
14331436
success: true
@@ -1603,7 +1606,7 @@ fn resolve_top_level() -> anyhow::Result<()> {
16031606
let requirements_in = context.temp_dir.child("requirements.in");
16041607
requirements_in.write_str("anyio>3.0.0")?;
16051608

1606-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
1609+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
16071610
.arg("--show-settings")
16081611
.arg("requirements.in"), @r###"
16091612
success: true
@@ -1742,7 +1745,7 @@ fn resolve_top_level() -> anyhow::Result<()> {
17421745
let requirements_in = context.temp_dir.child("requirements.in");
17431746
requirements_in.write_str("anyio>3.0.0")?;
17441747

1745-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
1748+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
17461749
.arg("--show-settings")
17471750
.arg("requirements.in"), @r###"
17481751
success: true
@@ -1922,7 +1925,7 @@ fn resolve_top_level() -> anyhow::Result<()> {
19221925
);
19231926

19241927
// But the command-line should take precedence over both.
1925-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
1928+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
19261929
.arg("--show-settings")
19271930
.arg("requirements.in")
19281931
.arg("--resolution=lowest-direct"), @r###"
@@ -2127,7 +2130,7 @@ fn resolve_user_configuration() -> anyhow::Result<()> {
21272130
requirements_in.write_str("anyio>3.0.0")?;
21282131

21292132
// Resolution should use the lowest direct version.
2130-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
2133+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
21312134
.arg("--show-settings")
21322135
.arg("requirements.in")
21332136
.env(EnvVars::XDG_CONFIG_HOME, xdg.path()), @r###"
@@ -2256,7 +2259,7 @@ fn resolve_user_configuration() -> anyhow::Result<()> {
22562259
"})?;
22572260

22582261
// Resolution should use the lowest direct version and generate hashes.
2259-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
2262+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
22602263
.arg("--show-settings")
22612264
.arg("requirements.in")
22622265
.env(EnvVars::XDG_CONFIG_HOME, xdg.path()), @r###"
@@ -2385,7 +2388,7 @@ fn resolve_user_configuration() -> anyhow::Result<()> {
23852388
"#})?;
23862389

23872390
// Resolution should use the highest version.
2388-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
2391+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
23892392
.arg("--show-settings")
23902393
.arg("requirements.in")
23912394
.env(EnvVars::XDG_CONFIG_HOME, xdg.path()), @r###"
@@ -2516,7 +2519,7 @@ fn resolve_user_configuration() -> anyhow::Result<()> {
25162519
"#})?;
25172520

25182521
// Resolution should use the highest version.
2519-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
2522+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
25202523
.arg("--show-settings")
25212524
.arg("requirements.in")
25222525
.env(EnvVars::XDG_CONFIG_HOME, xdg.path()), @r###"
@@ -2666,7 +2669,7 @@ fn resolve_tool() -> anyhow::Result<()> {
26662669

26672670
// If we're running a user-level command, like `uv tool install`, we should use lowest direct,
26682671
// but retain build isolation (since we ignore the local configuration).
2669-
uv_snapshot!(context.filters(), add_shared_args(context.tool_install())
2672+
uv_snapshot!(context.filters(), add_shared_args(context.tool_install(), context.temp_dir.path())
26702673
.arg("--show-settings")
26712674
.arg("requirements.in")
26722675
.env(EnvVars::XDG_CONFIG_HOME, xdg.path()), @r###"
@@ -2825,7 +2828,7 @@ fn resolve_poetry_toml() -> anyhow::Result<()> {
28252828
requirements_in.write_str("anyio>3.0.0")?;
28262829

28272830
// Resolution should use the lowest direct version, and generate hashes.
2828-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
2831+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
28292832
.arg("--show-settings")
28302833
.arg("requirements.in"), @r###"
28312834
success: true
@@ -2982,7 +2985,7 @@ fn resolve_both() -> anyhow::Result<()> {
29822985
requirements_in.write_str("anyio>3.0.0")?;
29832986

29842987
// Resolution should succeed, but warn that the `pip` section in `pyproject.toml` is ignored.
2985-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
2988+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
29862989
.arg("--show-settings")
29872990
.arg("requirements.in"), @r###"
29882991
success: true
@@ -3156,7 +3159,7 @@ fn invalid_conflicts() -> anyhow::Result<()> {
31563159
"#})?;
31573160

31583161
// The file should be rejected for violating the schema.
3159-
uv_snapshot!(context.filters(), add_shared_args(context.lock()), @r###"
3162+
uv_snapshot!(context.filters(), add_shared_args(context.lock(), context.temp_dir.path()), @r###"
31603163
success: false
31613164
exit_code: 2
31623165
----- stdout -----
@@ -3183,7 +3186,7 @@ fn invalid_conflicts() -> anyhow::Result<()> {
31833186
"#})?;
31843187

31853188
// The file should be rejected for violating the schema.
3186-
uv_snapshot!(context.filters(), add_shared_args(context.lock()), @r###"
3189+
uv_snapshot!(context.filters(), add_shared_args(context.lock(), context.temp_dir.path()), @r###"
31873190
success: false
31883191
exit_code: 2
31893192
----- stdout -----
@@ -3219,7 +3222,7 @@ fn valid_conflicts() -> anyhow::Result<()> {
32193222
[{extra = "x1"}, {extra = "x2"}],
32203223
]
32213224
"#})?;
3222-
uv_snapshot!(context.filters(), add_shared_args(context.lock()), @r###"
3225+
uv_snapshot!(context.filters(), add_shared_args(context.lock(), context.temp_dir.path()), @r###"
32233226
success: true
32243227
exit_code: 0
32253228
----- stdout -----
@@ -3255,7 +3258,7 @@ fn resolve_config_file() -> anyhow::Result<()> {
32553258
let requirements_in = context.temp_dir.child("requirements.in");
32563259
requirements_in.write_str("anyio>3.0.0")?;
32573260

3258-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
3261+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
32593262
.arg("--show-settings")
32603263
.arg("--config-file")
32613264
.arg(config.path())
@@ -3420,7 +3423,7 @@ fn resolve_config_file() -> anyhow::Result<()> {
34203423
"#})?;
34213424

34223425
// The file should be rejected for violating the schema.
3423-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
3426+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
34243427
.arg("--show-settings")
34253428
.arg("--config-file")
34263429
.arg(config.path())
@@ -3454,7 +3457,7 @@ fn resolve_config_file() -> anyhow::Result<()> {
34543457
})?;
34553458

34563459
// The file should be rejected for violating the schema, with a custom warning.
3457-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
3460+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
34583461
.arg("--show-settings")
34593462
.arg("--config-file")
34603463
.arg(config.path())
@@ -3509,7 +3512,7 @@ fn resolve_skip_empty() -> anyhow::Result<()> {
35093512

35103513
// Resolution in `child` should use lowest-direct, skipping the `pyproject.toml`, which lacks a
35113514
// `tool.uv`.
3512-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
3515+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
35133516
.arg("--show-settings")
35143517
.arg("requirements.in")
35153518
.current_dir(&child), @r###"
@@ -3641,7 +3644,7 @@ fn resolve_skip_empty() -> anyhow::Result<()> {
36413644
[tool.uv]
36423645
"#})?;
36433646

3644-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
3647+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
36453648
.arg("--show-settings")
36463649
.arg("requirements.in")
36473650
.current_dir(&child), @r###"
@@ -3782,7 +3785,7 @@ fn allow_insecure_host() -> anyhow::Result<()> {
37823785
let requirements_in = context.temp_dir.child("requirements.in");
37833786
requirements_in.write_str("anyio>3.0.0")?;
37843787

3785-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
3788+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
37863789
.arg("--show-settings")
37873790
.arg("requirements.in"), @r###"
37883791
success: true
@@ -3934,7 +3937,7 @@ fn index_priority() -> anyhow::Result<()> {
39343937
let requirements_in = context.temp_dir.child("requirements.in");
39353938
requirements_in.write_str("anyio>3.0.0")?;
39363939

3937-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
3940+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
39383941
.arg("requirements.in")
39393942
.arg("--show-settings")
39403943
.arg("--index-url")
@@ -4117,7 +4120,7 @@ fn index_priority() -> anyhow::Result<()> {
41174120
"###
41184121
);
41194122

4120-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
4123+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
41214124
.arg("requirements.in")
41224125
.arg("--show-settings")
41234126
.arg("--default-index")
@@ -4306,7 +4309,7 @@ fn index_priority() -> anyhow::Result<()> {
43064309
"#})?;
43074310

43084311
// Prefer the `--default-index` from the CLI, and treat it as the default.
4309-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
4312+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
43104313
.arg("requirements.in")
43114314
.arg("--show-settings")
43124315
.arg("--default-index")
@@ -4490,7 +4493,7 @@ fn index_priority() -> anyhow::Result<()> {
44904493
);
44914494

44924495
// Prefer the `--index` from the CLI, but treat the index from the file as the default.
4493-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
4496+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
44944497
.arg("requirements.in")
44954498
.arg("--show-settings")
44964499
.arg("--index")
@@ -4681,7 +4684,7 @@ fn index_priority() -> anyhow::Result<()> {
46814684
"#})?;
46824685

46834686
// Prefer the `--index-url` from the CLI, and treat it as the default.
4684-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
4687+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
46854688
.arg("requirements.in")
46864689
.arg("--show-settings")
46874690
.arg("--index-url")
@@ -4865,7 +4868,7 @@ fn index_priority() -> anyhow::Result<()> {
48654868
);
48664869

48674870
// Prefer the `--extra-index-url` from the CLI, but not as the default.
4868-
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile())
4871+
uv_snapshot!(context.filters(), add_shared_args(context.pip_compile(), context.temp_dir.path())
48694872
.arg("requirements.in")
48704873
.arg("--show-settings")
48714874
.arg("--extra-index-url")
@@ -5063,7 +5066,7 @@ fn verify_hashes() -> anyhow::Result<()> {
50635066
let requirements_in = context.temp_dir.child("requirements.in");
50645067
requirements_in.write_str("anyio>3.0.0")?;
50655068

5066-
uv_snapshot!(context.filters(), add_shared_args(context.pip_install())
5069+
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
50675070
.arg("-r")
50685071
.arg("requirements.in")
50695072
.arg("--show-settings"), @r###"
@@ -5185,7 +5188,7 @@ fn verify_hashes() -> anyhow::Result<()> {
51855188
"###
51865189
);
51875190

5188-
uv_snapshot!(context.filters(), add_shared_args(context.pip_install())
5191+
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
51895192
.arg("-r")
51905193
.arg("requirements.in")
51915194
.arg("--no-verify-hashes")
@@ -5306,7 +5309,7 @@ fn verify_hashes() -> anyhow::Result<()> {
53065309
"###
53075310
);
53085311

5309-
uv_snapshot!(context.filters(), add_shared_args(context.pip_install())
5312+
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
53105313
.arg("-r")
53115314
.arg("requirements.in")
53125315
.arg("--require-hashes")
@@ -5429,7 +5432,7 @@ fn verify_hashes() -> anyhow::Result<()> {
54295432
"###
54305433
);
54315434

5432-
uv_snapshot!(context.filters(), add_shared_args(context.pip_install())
5435+
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
54335436
.arg("-r")
54345437
.arg("requirements.in")
54355438
.arg("--no-require-hashes")
@@ -5550,7 +5553,7 @@ fn verify_hashes() -> anyhow::Result<()> {
55505553
"###
55515554
);
55525555

5553-
uv_snapshot!(context.filters(), add_shared_args(context.pip_install())
5556+
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
55545557
.arg("-r")
55555558
.arg("requirements.in")
55565559
.env("UV_NO_VERIFY_HASHES", "1")
@@ -5671,7 +5674,7 @@ fn verify_hashes() -> anyhow::Result<()> {
56715674
"###
56725675
);
56735676

5674-
uv_snapshot!(context.filters(), add_shared_args(context.pip_install())
5677+
uv_snapshot!(context.filters(), add_shared_args(context.pip_install(), context.temp_dir.path())
56755678
.arg("-r")
56765679
.arg("requirements.in")
56775680
.arg("--verify-hashes")

0 commit comments

Comments
 (0)