Skip to content

Commit 68a46a6

Browse files
Save/restore os.environ correctly
1 parent a2e41cc commit 68a46a6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tests/test_api_endpoint_config.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,30 @@ def test_default_api_endpoint(self):
1818
# When no env var is set, it should default to models.github.ai/inference
1919
try:
2020
# Save original env
21-
original_env = os.environ
22-
os.environ.pop('AI_API_ENDPOINT', None)
21+
original_env = os.environ.pop('AI_API_ENDPOINT', None)
2322
endpoint = get_AI_endpoint()
2423
assert endpoint is not None
2524
assert isinstance(endpoint, str)
2625
assert urlparse(endpoint).netloc == AI_API_ENDPOINT_ENUM.AI_API_MODELS_GITHUB
2726
finally:
2827
# Restore original env
29-
os.environ = original_env
28+
if original_env:
29+
os.environ['AI_API_ENDPOINT'] = original_env
3030

3131
def test_api_endpoint_env_override(self):
3232
"""Test that AI_API_ENDPOINT can be overridden by environment variable."""
3333
try:
3434
# Save original env
35-
original_env = os.environ
35+
original_env = os.environ.pop('AI_API_ENDPOINT', None)
3636
# Set different endpoint
3737
test_endpoint = 'https://api.githubcopilot.com'
3838
os.environ['AI_API_ENDPOINT'] = test_endpoint
3939

4040
assert get_AI_endpoint() == test_endpoint
4141
finally:
4242
# Restore original env
43-
os.environ = original_env
43+
if original_env:
44+
os.environ['AI_API_ENDPOINT'] = original_env
4445

4546
if __name__ == '__main__':
4647
pytest.main([__file__, '-v'])

0 commit comments

Comments
 (0)