Skip to content

Commit 920de24

Browse files
committed
updates module setup process for specific environs w/o creds
1 parent bb3737d commit 920de24

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

packages/google-cloud-logging/tests/system/test_system.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,24 @@ class Config(object):
105105

106106

107107
def setUpModule():
108-
Config.CLIENT = client.Client()
109-
Config.HTTP_CLIENT = client.Client(_use_grpc=False)
108+
# Use GOOGLE_CLOUD_PROJECT
109+
project_id = os.environ.get("GOOGLE_CLOUD_PROJECT")
110+
111+
# Check if we have credentials (either via file or environment)
112+
# google.auth.default() will check GOOGLE_APPLICATION_CREDENTIALS
113+
has_creds = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS") is not None
114+
115+
# Guard: Skip the entire module if the environment is not ready
116+
if not project_id or not has_creds:
117+
raise unittest.SkipTest(
118+
"System tests skipped: GOOGLE_CLOUD_PROJECT and "
119+
"GOOGLE_APPLICATION_CREDENTIALS must be set."
120+
)
110121

122+
# Explicitly pass the project to the client
123+
# This prevents the client from attempting 'discovery' via the metadata server
124+
Config.CLIENT = client.Client(project=project_id)
125+
Config.HTTP_CLIENT = client.Client(_use_grpc=False, project=project_id)
111126

112127
# Skip the test cases using bigquery, storage and pubsub clients for mTLS testing.
113128
# Bigquery and storage uses http which doesn't have mTLS support, pubsub doesn't

0 commit comments

Comments
 (0)