Skip to content

Commit

Permalink
Fix flaky regrid test by clearing LRU cache after each test (#2322)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Schlund <[email protected]>
  • Loading branch information
valeriupredoi and schlunma authored Feb 5, 2024
1 parent 70b1956 commit 3700cc9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/unit/preprocessor/_regrid/test__stock_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def setUp(self):
'iris.coords.DimCoord', return_value=self.mock_coord)
self.mocks = [self.mock_Cube, self.mock_coord, self.mock_DimCoord]

def tearDown(self) -> None:
_global_stock_cube.cache_clear()
return super().tearDown()

def test_invalid_cell_spec__alpha(self):
emsg = 'Invalid MxN cell specification'
with self.assertRaisesRegex(ValueError, emsg):
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/preprocessor/_regrid/test_extract_regional_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
regrid,
)


@pytest.fixture(autouse=True)
def clear_lru_cache():
"""Make sure to clear LRU cache for ``_global_stock_cube``.
See https://github.com/ESMValGroup/ESMValCore/issues/2320.
"""
yield # execute tests
_global_stock_cube.cache_clear()


SPEC_KEYS = ('start_longitude', 'end_longitude', 'step_longitude',
'start_latitude', 'end_latitude', 'step_latitude')
PASSING_SPECS = tuple(
Expand Down Expand Up @@ -44,7 +56,6 @@
))


@pytest.mark.xfail
@pytest.mark.parametrize('spec', PASSING_SPECS)
def test_extract_regional_grid_passing(spec):
"""Test regridding with regional target spec."""
Expand Down

0 comments on commit 3700cc9

Please sign in to comment.