Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/tests-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Set up Earth Engine
env:
EE_TOKEN: ${{ secrets.EE_TOKEN }}
run: |
mkdir -p /home/runner/.config/earthengine
echo "$EE_TOKEN" > /home/runner/.config/earthengine/credentials
- name: Test with pytest
env:
EE_SERVICE_ACCOUNT: ${{ secrets.EE_SERVICE_ACCOUNT }}
run: |
hatch run test:coverage --cov-report=xml
- name: Upload to Codecov
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Set up Earth Engine
env:
EE_TOKEN: ${{ secrets.EE_TOKEN }}
run: |
mkdir -p /home/runner/.config/earthengine
echo "$EE_TOKEN" > /home/runner/.config/earthengine/credentials
- name: Test with pytest
env:
EE_SERVICE_ACCOUNT: ${{ secrets.EE_SERVICE_ACCOUNT }}
run: |
hatch run test:all
22 changes: 20 additions & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import wxee
import os
import json

import ee


def pytest_sessionstart(session):
Expand All @@ -7,7 +10,7 @@ def pytest_sessionstart(session):
"""
if not is_ee_excluded(session):
try:
wxee.Initialize()
_init_ee_for_tests()
except Exception:
raise ValueError(
'Earth Engine could not be initialized. Use `pytest . -m "not ee"` to skip Earth Engine tests.'
Expand All @@ -18,3 +21,18 @@ def is_ee_excluded(session):
"""Check if a marker filter was passed to the session to exclude tests marked `ee`."""
markers = session.config.getoption("-m")
return "not ee" in markers


def _init_ee_for_tests():
# Use the Github Service Account for CI tests
if os.environ.get("GITHUB_ACTIONS"):
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, project=project_id)
Loading