From a91b7ee5c2ba439321bf3c835b698bf19c6d8b63 Mon Sep 17 00:00:00 2001 From: Igor Lins e Silva <4753812+igorls@users.noreply.github.com> Date: Sun, 3 May 2026 06:27:37 -0300 Subject: [PATCH] test(cli): prime monkeypatch undo so palace env doesn't leak monkeypatch.delenv(name, raising=False) on a missing key registers no undo entry, so the env var cmd_init writes leaked into test_config_from_file on Python 3.13 / Windows / macOS. Prime the slot with setenv before delenv so teardown rolls back the write. --- tests/test_cli.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index c52e67f..04442d0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -187,9 +187,15 @@ def test_cmd_init_honors_palace_flag(tmp_path, monkeypatch): palace = tmp_path / "custom_palace" # Make sure no leftover env var from another test leaks in — we want to - # verify that --palace ALONE drives the resolution. - monkeypatch.delenv("MEMPALACE_PALACE_PATH", raising=False) - monkeypatch.delenv("MEMPAL_PALACE_PATH", raising=False) + # verify that --palace ALONE drives the resolution. Prime monkeypatch's + # undo list with setenv first so that the env var ``cmd_init`` writes + # below is rolled back at teardown (``delenv(raising=False)`` on a + # missing key registers no undo entry, which would leak into the next + # test). + monkeypatch.setenv("MEMPALACE_PALACE_PATH", "") + monkeypatch.setenv("MEMPAL_PALACE_PATH", "") + monkeypatch.delenv("MEMPALACE_PALACE_PATH") + monkeypatch.delenv("MEMPAL_PALACE_PATH") args = argparse.Namespace( dir=str(project),