From ea943fab26449d8ccc22d8e657b10fceb7f85265 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Wed, 24 Jan 2024 10:34:04 +0100 Subject: [PATCH 1/4] enabled tests with secrets --- .github/workflows/pytest.yml | 2 +- tests/test_download.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 5aba9c2c9..e7a1ce982 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -41,5 +41,5 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | - pytest -m "not requireslocaldata" --cov=dfm_tools --cov-report xml --cov-report term + pytest -m "requiressecrets" --cov=dfm_tools --cov-report xml --cov-report term - uses: codecov/codecov-action@v1 diff --git a/tests/test_download.py b/tests/test_download.py index abada1e95..fde71571e 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -12,6 +12,7 @@ import dfm_tools as dfmt +@pytest.mark.requiressecrets @pytest.mark.requireslocaldata @pytest.mark.unittest def test_cds_credentials(): @@ -24,6 +25,7 @@ def test_cds_credentials(): #TODO: properly set environment variables in github would prevent localness +@pytest.mark.requiressecrets @pytest.mark.requireslocaldata @pytest.mark.unittest def test_copernicusmarine_credentials(): @@ -31,6 +33,7 @@ def test_copernicusmarine_credentials(): #TODO: properly set environment variables in github would prevent localness +@pytest.mark.requiressecrets @pytest.mark.requireslocaldata @pytest.mark.unittest def test_download_era5(tmp_path): @@ -46,6 +49,7 @@ def test_download_era5(tmp_path): #TODO: properly set environment variables in github would prevent localness +@pytest.mark.requiressecrets @pytest.mark.requireslocaldata @pytest.mark.unittest def test_download_cmems_my(tmp_path): @@ -62,6 +66,7 @@ def test_download_cmems_my(tmp_path): #TODO: properly set environment variables in github would prevent localness +@pytest.mark.requiressecrets @pytest.mark.requireslocaldata @pytest.mark.unittest def test_download_cmems_forecast(tmp_path): From f1370a0adac449f38e29987df08f6f8cb1859966 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Wed, 24 Jan 2024 10:55:11 +0100 Subject: [PATCH 2/4] using secrets in workflow --- .github/workflows/pytest.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index e7a1ce982..0b2d4728c 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -40,6 +40,10 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest + env: + CDSAPI_KEY: ${{ secrets.CDSAPI_KEY }} + COPERNICUS_MARINE_SERVICE_USERNAME: ${{ secrets.COPERNICUS_MARINE_SERVICE_USERNAME }} + COPERNICUS_MARINE_SERVICE_PASSWORD: ${{ secrets.COPERNICUS_MARINE_SERVICE_PASSWORD }} run: | pytest -m "requiressecrets" --cov=dfm_tools --cov-report xml --cov-report term - uses: codecov/codecov-action@v1 From 108a0c04cc1259ebef72102609316cf2e298c679 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Wed, 24 Jan 2024 11:01:24 +0100 Subject: [PATCH 3/4] pass to other testbanks and cleanup code --- .github/workflows/pytest-py312.yml | 4 ++++ .github/workflows/pytest-py313.yml | 4 ++++ .github/workflows/pytest-py39-mindeps.yml | 4 ++++ .github/workflows/pytest.yml | 2 +- tests/test_download.py | 14 -------------- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pytest-py312.yml b/.github/workflows/pytest-py312.yml index b6c2539c9..016eaf164 100644 --- a/.github/workflows/pytest-py312.yml +++ b/.github/workflows/pytest-py312.yml @@ -36,6 +36,10 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest + env: + CDSAPI_KEY: ${{ secrets.CDSAPI_KEY }} + COPERNICUS_MARINE_SERVICE_USERNAME: ${{ secrets.COPERNICUS_MARINE_SERVICE_USERNAME }} + COPERNICUS_MARINE_SERVICE_PASSWORD: ${{ secrets.COPERNICUS_MARINE_SERVICE_PASSWORD }} run: | pytest -m "not requireslocaldata" --cov=dfm_tools --cov-report xml --cov-report term - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/pytest-py313.yml b/.github/workflows/pytest-py313.yml index efa7fc1e6..0e136f55c 100644 --- a/.github/workflows/pytest-py313.yml +++ b/.github/workflows/pytest-py313.yml @@ -36,6 +36,10 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest + env: + CDSAPI_KEY: ${{ secrets.CDSAPI_KEY }} + COPERNICUS_MARINE_SERVICE_USERNAME: ${{ secrets.COPERNICUS_MARINE_SERVICE_USERNAME }} + COPERNICUS_MARINE_SERVICE_PASSWORD: ${{ secrets.COPERNICUS_MARINE_SERVICE_PASSWORD }} run: | pytest -m "not requireslocaldata" --cov=dfm_tools --cov-report xml --cov-report term - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/pytest-py39-mindeps.yml b/.github/workflows/pytest-py39-mindeps.yml index 90eb0f181..17f719151 100644 --- a/.github/workflows/pytest-py39-mindeps.yml +++ b/.github/workflows/pytest-py39-mindeps.yml @@ -41,6 +41,10 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest + env: + CDSAPI_KEY: ${{ secrets.CDSAPI_KEY }} + COPERNICUS_MARINE_SERVICE_USERNAME: ${{ secrets.COPERNICUS_MARINE_SERVICE_USERNAME }} + COPERNICUS_MARINE_SERVICE_PASSWORD: ${{ secrets.COPERNICUS_MARINE_SERVICE_PASSWORD }} run: | pytest -m "not requireslocaldata" --cov=dfm_tools --cov-report xml --cov-report term - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 0b2d4728c..6ecf2b00b 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -45,5 +45,5 @@ jobs: COPERNICUS_MARINE_SERVICE_USERNAME: ${{ secrets.COPERNICUS_MARINE_SERVICE_USERNAME }} COPERNICUS_MARINE_SERVICE_PASSWORD: ${{ secrets.COPERNICUS_MARINE_SERVICE_PASSWORD }} run: | - pytest -m "requiressecrets" --cov=dfm_tools --cov-report xml --cov-report term + pytest -m "not requireslocaldata" --cov=dfm_tools --cov-report xml --cov-report term - uses: codecov/codecov-action@v1 diff --git a/tests/test_download.py b/tests/test_download.py index fde71571e..6db9e68d2 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -12,8 +12,6 @@ import dfm_tools as dfmt -@pytest.mark.requiressecrets -@pytest.mark.requireslocaldata @pytest.mark.unittest def test_cds_credentials(): # check if the credentials are present on this system @@ -24,17 +22,11 @@ def test_cds_credentials(): assert "CDSAPI_URL" in os.environ.keys() -#TODO: properly set environment variables in github would prevent localness -@pytest.mark.requiressecrets -@pytest.mark.requireslocaldata @pytest.mark.unittest def test_copernicusmarine_credentials(): copernicusmarine_credentials() -#TODO: properly set environment variables in github would prevent localness -@pytest.mark.requiressecrets -@pytest.mark.requireslocaldata @pytest.mark.unittest def test_download_era5(tmp_path): date_min = '2010-01-01' @@ -48,9 +40,6 @@ def test_download_era5(tmp_path): dir_output=tmp_path, overwrite=True) -#TODO: properly set environment variables in github would prevent localness -@pytest.mark.requiressecrets -@pytest.mark.requireslocaldata @pytest.mark.unittest def test_download_cmems_my(tmp_path): date_min = '2010-01-01' @@ -65,9 +54,6 @@ def test_download_cmems_my(tmp_path): dir_output=tmp_path, file_prefix=file_prefix, overwrite=True) -#TODO: properly set environment variables in github would prevent localness -@pytest.mark.requiressecrets -@pytest.mark.requireslocaldata @pytest.mark.unittest def test_download_cmems_forecast(tmp_path): date_min = pd.Timestamp.today() From 829f60d1cb6636c09c52ab670927ac95a9cdeeb8 Mon Sep 17 00:00:00 2001 From: veenstrajelmer Date: Wed, 24 Jan 2024 11:03:38 +0100 Subject: [PATCH 4/4] add requiressecrets pytest marker --- pyproject.toml | 1 + tests/test_download.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index ea14dde0e..72f66e609 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,6 +106,7 @@ markers = [ "systemtest: mark a test as systemtest. Used for testing at a higher level, verifying a given input returns the expected output", "acceptance: mark a test as acceptance. Used for non-functional requirements and data that needs to be human-verified", "requireslocaldata: mark a test that cannot run on Github", + "requiressecrets: mark a test that requires environment variables to be set (e.g. via Github secrets)", ] [tool.flake8] diff --git a/tests/test_download.py b/tests/test_download.py index 6db9e68d2..8c712b29c 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -12,6 +12,7 @@ import dfm_tools as dfmt +@pytest.mark.requiressecrets @pytest.mark.unittest def test_cds_credentials(): # check if the credentials are present on this system @@ -22,11 +23,13 @@ def test_cds_credentials(): assert "CDSAPI_URL" in os.environ.keys() +@pytest.mark.requiressecrets @pytest.mark.unittest def test_copernicusmarine_credentials(): copernicusmarine_credentials() +@pytest.mark.requiressecrets @pytest.mark.unittest def test_download_era5(tmp_path): date_min = '2010-01-01' @@ -40,6 +43,7 @@ def test_download_era5(tmp_path): dir_output=tmp_path, overwrite=True) +@pytest.mark.requiressecrets @pytest.mark.unittest def test_download_cmems_my(tmp_path): date_min = '2010-01-01' @@ -54,6 +58,7 @@ def test_download_cmems_my(tmp_path): dir_output=tmp_path, file_prefix=file_prefix, overwrite=True) +@pytest.mark.requiressecrets @pytest.mark.unittest def test_download_cmems_forecast(tmp_path): date_min = pd.Timestamp.today()