Skip to content

Commit

Permalink
Merge pull request #103 from wri/CIF-323-Add-on-off-control-of-skippe…
Browse files Browse the repository at this point in the history
…d-tests-to-conftest-file

Adding a master control for ignored tests
  • Loading branch information
kcartier-wri authored Jan 3, 2025
2 parents df3e021 + 2e6a7b9 commit 782d9ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
from city_metrix.layers.layer import create_fishnet_grid
from geocube.api.core import make_geocube

# EXECUTE_IGNORED_TESTS is the master control for whether to execute tests decorated with
# pytest.mark.skipif. These tests are temporarily ignored due to some unresolved issue.
# Setting EXECUTE_IGNORED_TESTS to True turns on code execution. This should be done for local testing.
# The value must be set to False when pushing to GitHub since the ignored tests would otherwise fail
# in GitHub Actions.
EXECUTE_IGNORED_TESTS = False

def test_create_fishnet_grid(min_x, min_y, max_x, max_y, cell_size):
# Slightly reduce aoi to avoid partial cells
reduction = 0.000001
Expand Down
5 changes: 3 additions & 2 deletions tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
UrbanLandUse,
WorldPop
)
from tests.conftest import EXECUTE_IGNORED_TESTS
from tests.resources.bbox_constants import BBOX_BRA_LAURO_DE_FREITAS_1

# Tests are implemented for the same bounding box in Brazil.
Expand All @@ -53,12 +54,12 @@ def test_built_up_height():
data = BuiltUpHeight().get_data(BBOX)
assert np.size(data) > 0

@pytest.mark.skip(reason="CDS API needs personal access token file to run")
@pytest.mark.skipif(EXECUTE_IGNORED_TESTS == False, reason="CDS API needs personal access token file to run")
def test_cams():
data = Cams().get_data(BBOX)
assert np.size(data) > 0

@pytest.mark.skip(reason="CDS API needs personal access token file to run")
@pytest.mark.skipif(EXECUTE_IGNORED_TESTS == False, reason="CDS API needs personal access token file to run")
def test_era_5_hottest_day():
data = Era5HottestDay().get_data(BBOX)
assert np.size(data) > 0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from city_metrix import *
from .conftest import ZONES
from .conftest import ZONES, EXECUTE_IGNORED_TESTS
import pytest


Expand All @@ -24,7 +24,7 @@ def test_built_land_without_tree_cover():
assert expected_zone_size == actual_indicator_size


@pytest.mark.skip(reason="CDS API needs personal access token file to run")
@pytest.mark.skipif(EXECUTE_IGNORED_TESTS == False, reason="CDS API needs personal access token file to run")
def test_era_5_met_preprocess():
indicator = era_5_met_preprocessing(ZONES)
assert len(indicator) == 24
Expand Down

0 comments on commit 782d9ed

Please sign in to comment.