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 <noreply@anthropic.com>
This commit is contained in:
Matt Van Horn
2026-03-02 23:36:37 -08:00
parent d7bff81757
commit 04bfb5381d
+2 -1
View File
@@ -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")