diff --git a/tests/conftest.py b/tests/conftest.py index b3fe78a9..060eafb6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,11 +77,22 @@ def bind_inline_executor( spawner.bind(app.workflows.queue.executor) -@pytest.fixture +@pytest.fixture(autouse=True) def isolated_home(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Iterator[Path]: home = tmp_path / "home" home.mkdir() + # `home_dir()` resolves `~` through `Path.home()`. POSIX reads $HOME, but + # Windows reads %USERPROFILE% and ignores $HOME entirely, so patching only + # $HOME leaves user state pointing at the real `~/.codealmanac`. monkeypatch.setenv("HOME", str(home)) + monkeypatch.setenv("USERPROFILE", str(home)) + resolved = Path.home() + if resolved != home: + raise RuntimeError( + "isolated_home failed to redirect the user home: " + f"Path.home() is {resolved}, expected {home}. " + "Tests must never read or write the real ~/.codealmanac." + ) yield home