From 04bfb5381d8eb652204204d12d150c43b9091062 Mon Sep 17 00:00:00 2001 From: Matt Van Horn Date: Mon, 2 Mar 2026 23:36:37 -0800 Subject: [PATCH] fix(tests): patch env isolation in test_api_key_takes_priority The test was picking up the real OPENAI_API_KEY from the shell environment, causing it to fail on any machine with that key set. Added @patch.dict(os.environ, {}, clear=True) so the test runs in a clean env and exercises the file_env path as intended. Co-Authored-By: Claude Opus 4.6 --- tests/test_codex_auth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_codex_auth.py b/tests/test_codex_auth.py index 5634de0..595971e 100644 --- a/tests/test_codex_auth.py +++ b/tests/test_codex_auth.py @@ -74,8 +74,9 @@ class TestExtractChatgptAccountId(unittest.TestCase): class TestGetOpenaiAuth(unittest.TestCase): + @patch.dict(os.environ, {}, clear=True) def test_api_key_takes_priority(self): - """OPENAI_API_KEY in env file should be preferred over Codex.""" + """OPENAI_API_KEY in env file is used when env var is not set.""" file_env = {"OPENAI_API_KEY": "sk-test123"} auth = env.get_openai_auth(file_env) self.assertEqual(auth.source, "api_key")