Skip to content

Commit f8a6db6

Browse files
committed
test(kanban): isolate HERMES_KANBAN_BOARD writes in pin-env tests
The helper under test writes to os.environ directly, bypassing monkeypatch tracking. Without an explicit snapshot/restore fixture, the mutation leaks into subsequent tests and breaks TestSharedBoardPaths (kanban path resolution reads HERMES_KANBAN_BOARD and routes through boards/<leaked-slug>/ instead of the test's own HERMES_HOME). Add an autouse fixture that snapshots the env var before the test and restores (or pops) it after, regardless of what the helper did.
1 parent b22b3f5 commit f8a6db6

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

tests/hermes_cli/test_pin_kanban_board_env.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,32 @@
88
shell calls to a different DB.
99
"""
1010
import importlib
11+
import os
12+
13+
import pytest
14+
15+
16+
@pytest.fixture(autouse=True)
17+
def _isolate_kanban_board_env():
18+
"""Snapshot `HERMES_KANBAN_BOARD` and restore it after the test.
19+
20+
`_pin_kanban_board_env()` writes to ``os.environ`` directly, bypassing
21+
any ``monkeypatch.setenv`` tracking. Without this fixture the mutation
22+
leaks into subsequent tests and breaks anything that resolves a kanban
23+
path from the env (e.g. ``TestSharedBoardPaths`` in test_kanban_db.py).
24+
"""
25+
prev = os.environ.get("HERMES_KANBAN_BOARD")
26+
os.environ.pop("HERMES_KANBAN_BOARD", None)
27+
try:
28+
yield
29+
finally:
30+
if prev is None:
31+
os.environ.pop("HERMES_KANBAN_BOARD", None)
32+
else:
33+
os.environ["HERMES_KANBAN_BOARD"] = prev
1134

1235

1336
def test_pin_writes_resolved_board_when_env_unset(monkeypatch):
14-
monkeypatch.delenv("HERMES_KANBAN_BOARD", raising=False)
1537
main_mod = importlib.import_module("hermes_cli.main")
1638

1739
import hermes_cli.kanban_db as kdb
@@ -39,7 +61,6 @@ def _explode():
3961

4062

4163
def test_pin_swallows_resolution_failures(monkeypatch):
42-
monkeypatch.delenv("HERMES_KANBAN_BOARD", raising=False)
4364
main_mod = importlib.import_module("hermes_cli.main")
4465

4566
import hermes_cli.kanban_db as kdb

0 commit comments

Comments
 (0)