fix(ci): eliminate test_set_key flakiness — v0.50.161
Root cause: test_profile_env_isolation.py and test_profile_path_security.py called sys.modules.pop() without restoring, poisoning subsequent tests. Fix: monkeypatch.delitem so pytest auto-restores. Also holds _ENV_LOCK for full I/O cycle in _write_env_file and creates .env at 0600 via os.open. Reviewed by Opus (no independent review needed — test/providers fix only).
This commit is contained in:
@@ -18,9 +18,10 @@ def test_profile_switch_clears_previous_profile_env_vars(monkeypatch, tmp_path):
|
||||
monkeypatch.delenv("OPENAI_API_KEY", raising=False)
|
||||
monkeypatch.delenv("CUSTOM_TOKEN", raising=False)
|
||||
|
||||
sys.modules.pop("api.profiles", None)
|
||||
# Use monkeypatch so sys.modules is restored after the test, preventing
|
||||
# api.profiles from being permanently removed and poisoning subsequent tests.
|
||||
monkeypatch.delitem(sys.modules, "api.profiles", raising=False)
|
||||
profiles = importlib.import_module("api.profiles")
|
||||
profiles = importlib.reload(profiles)
|
||||
|
||||
profiles.init_profile_state()
|
||||
profiles.switch_profile("p1")
|
||||
@@ -52,9 +53,10 @@ def test_profile_switch_replaces_overlapping_keys(monkeypatch, tmp_path):
|
||||
monkeypatch.delenv("ONLY_P1", raising=False)
|
||||
monkeypatch.delenv("ONLY_P2", raising=False)
|
||||
|
||||
sys.modules.pop("api.profiles", None)
|
||||
# Use monkeypatch so sys.modules is restored after the test, preventing
|
||||
# api.profiles from being permanently removed and poisoning subsequent tests.
|
||||
monkeypatch.delitem(sys.modules, "api.profiles", raising=False)
|
||||
profiles = importlib.import_module("api.profiles")
|
||||
profiles = importlib.reload(profiles)
|
||||
|
||||
profiles.init_profile_state()
|
||||
profiles.switch_profile("p1")
|
||||
|
||||
Reference in New Issue
Block a user