Skip to content

Commit 20f3b7d

Browse files
twishabansalanubhav756
authored andcommitted
tests(langchain-sdk): Update conftest to be able to run tests in local
1 parent 9b42f2b commit 20f3b7d

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/conftest.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,25 @@ def get_toolbox_binary_url(toolbox_version: str) -> str:
8181

8282
def get_auth_token(client_id: str) -> str:
8383
"""Retrieves an authentication token"""
84-
request = google.auth.transport.requests.Request()
85-
credentials = compute_engine.IDTokenCredentials(
86-
request=request,
87-
target_audience=client_id,
88-
use_metadata_identity_endpoint=True,
89-
)
90-
if not credentials.valid:
91-
credentials.refresh(request)
92-
return credentials.token
84+
try:
85+
# Try getting the token using gcloud (for local development)
86+
result = subprocess.run(
87+
["gcloud", "auth", "print-identity-token"],
88+
capture_output=True,
89+
text=True,
90+
check=True,
91+
)
92+
return result.stdout.strip()
93+
except (subprocess.CalledProcessError, FileNotFoundError):
94+
request = google.auth.transport.requests.Request()
95+
credentials = compute_engine.IDTokenCredentials(
96+
request=request,
97+
target_audience=client_id,
98+
use_metadata_identity_endpoint=True,
99+
)
100+
if not credentials.valid:
101+
credentials.refresh(request)
102+
return credentials.token
93103

94104

95105
#### Define Fixtures

0 commit comments

Comments
 (0)