Skip to content

Commit 9bdbd82

Browse files
committed
tests: refactor system tests
1 parent 62a75ec commit 9bdbd82

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/google-auth/system_tests/system_tests_sync/test_compute_engine.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from datetime import datetime
1616

17+
import os
1718
import pytest
1819

1920
import google.auth
@@ -29,11 +30,23 @@
2930

3031
@pytest.fixture(autouse=True)
3132
def check_gce_environment(http_request):
33+
# 1. Verify we are actually on a GCE instance
3234
try:
3335
_metadata.get_service_account_info(http_request)
3436
except exceptions.TransportError:
3537
pytest.skip("Compute Engine metadata service is not available.")
3638

39+
# 2. Prevent local Service Account key from overriding GCE credentials
40+
original_creds = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")
41+
if "GOOGLE_APPLICATION_CREDENTIALS" in os.environ:
42+
del os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
43+
44+
yield
45+
46+
# 3. Restore environment after the test
47+
if original_creds is not None:
48+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = original_creds
49+
3750

3851
def test_refresh(http_request, token_info):
3952
credentials = compute_engine.Credentials()

0 commit comments

Comments
 (0)