Skip to content

Commit

Permalink
Parse project_id from service account key data
Browse files Browse the repository at this point in the history
  • Loading branch information
aazuspan committed Jan 29, 2025
1 parent ea8fbed commit dea4f4a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,22 @@ def object_cache():


def pytest_sessionstart(session):
_init_ee_for_tests()


def _init_ee_for_tests():
# Use the Github Service Account for CI tests
if os.environ.get("GITHUB_ACTIONS"):
service_account = os.environ.get("EE_SERVICE_ACCOUNT")
credentials = ee.ServiceAccountCredentials(None, key_data=service_account)
key_data = os.environ.get("EE_SERVICE_ACCOUNT")
project_id = json.loads(key_data).get("project_id")
credentials = ee.ServiceAccountCredentials(None, key_data=key_data)
# Use stored persistent credentials for local tests
else:
# Project should be parsed from credentials
project_id = None
credentials = "persistent"

ee.Initialize(credentials=credentials)
ee.Initialize(credentials, project=project_id)


@pytest.fixture(autouse=True)
Expand Down

0 comments on commit dea4f4a

Please sign in to comment.