Skip to content

Commit 97557ae

Browse files
authored
fix(test-smoke): set USERPROFILE alongside HOME for Windows Path.home() compat (#439)
1 parent acf3408 commit 97557ae

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

tests/smoke/conftest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,22 @@ def console_script_command(script_name: str, module_name: str) -> list[str]:
6666
return [sys.executable, "-m", module_name]
6767

6868

69-
def smoke_env(**overrides: str) -> dict[str, str]:
69+
def smoke_env(
70+
*,
71+
home: str | Path | None = None,
72+
**overrides: str,
73+
) -> dict[str, str]:
7074
env = os.environ.copy()
7175
cwd = str(Path.cwd())
7276
pythonpath = env.get("PYTHONPATH")
7377
env["PYTHONPATH"] = cwd if not pythonpath else f"{cwd}{os.pathsep}{pythonpath}"
78+
if home is not None:
79+
home_value = str(home)
80+
env["HOME"] = home_value
81+
env["USERPROFILE"] = home_value
7482
env.update(overrides)
83+
if "HOME" in overrides and "USERPROFILE" not in overrides:
84+
env["USERPROFILE"] = overrides["HOME"]
7585
return env
7686

7787

tests/smoke/test_cli_configure_smoke.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ def test_cli_configure_rejects_no_value_no_stdin_in_non_tty() -> None:
2929
def test_cli_configure_inline_value_works_non_interactively(tmp_path) -> None:
3030
"""v2: inline-value form is the supported automation path for install
3131
scripts; must work without a TTY."""
32-
env = smoke_env()
33-
env["HOME"] = str(tmp_path)
32+
env = smoke_env(home=tmp_path)
3433
result = subprocess.run(
3534
[sys.executable, "-m", "autosearch.cli.main", "configure", "SMOKE_KEY", "smokeval"],
3635
input="",

tests/smoke/test_install_script.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import pytest
77

8+
from tests.smoke.conftest import smoke_env
9+
810

911
ROOT = Path(__file__).resolve().parents[2]
1012
NPM_DIR = ROOT / "npm"
@@ -70,8 +72,7 @@ def test_install_then_run_e2e_smoke(tmp_path: Path) -> None:
7072
)
7173
fake_bash.chmod(0o755)
7274

73-
env = os.environ.copy()
74-
env["HOME"] = str(home)
75+
env = smoke_env(home=home)
7576
env["PATH"] = os.pathsep.join([str(fake_bin), "/usr/bin", "/bin"])
7677

7778
result = subprocess.run(

tests/smoke/test_npm_wrapper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import pytest
88

9+
from tests.smoke.conftest import smoke_env
10+
911

1012
ROOT = Path(__file__).resolve().parents[2]
1113
NPM_DIR = ROOT / "npm"
@@ -133,8 +135,7 @@ def test_path_after_install_finds_binary(tmp_path: Path) -> None:
133135
)
134136
fake_bash.chmod(0o755)
135137

136-
env = os.environ.copy()
137-
env["HOME"] = str(home)
138+
env = smoke_env(home=home)
138139
env["PATH"] = os.pathsep.join([str(fake_bin), "/usr/bin", "/bin"])
139140

140141
result = subprocess.run(
@@ -179,8 +180,7 @@ def test_install_passes_no_init(tmp_path: Path) -> None:
179180
)
180181
fake_bash.chmod(0o755)
181182

182-
env = os.environ.copy()
183-
env["HOME"] = str(home)
183+
env = smoke_env(home=home)
184184
env["PATH"] = os.pathsep.join([str(fake_bin), "/usr/bin", "/bin"])
185185

186186
result = subprocess.run(

0 commit comments

Comments
 (0)