Skip to content

Commit

Permalink
Always ignore user's configuration when running Dask tests (#2624)
Browse files Browse the repository at this point in the history
  • Loading branch information
schlunma authored Dec 20, 2024
1 parent 90e12d4 commit 85526a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
12 changes: 10 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@

import esmvalcore.config._dask
from esmvalcore.config import CFG, Config
from esmvalcore.config._config_object import _get_global_config


@pytest.fixture
def cfg_default(mocker):
def cfg_default():
"""Create a configuration object with default values."""
cfg = deepcopy(CFG)
cfg = _get_global_config()
cfg.load_from_dirs([])
return cfg


@pytest.fixture()
def ignore_existing_user_config(monkeypatch, cfg_default):
"""Ignore user's configuration when running tests."""
for key, value in cfg_default.items():
monkeypatch.setitem(CFG, key, deepcopy(value))


@pytest.fixture
def session(tmp_path: Path, cfg_default, monkeypatch):
"""Session object with default settings."""
Expand Down
25 changes: 19 additions & 6 deletions tests/unit/config/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def mock_dask_config_set(mocker):
return mock_dask_set


def test_get_no_distributed_client():
def test_get_no_distributed_client(ignore_existing_user_config):
with _dask.get_distributed_client() as client:
assert client is None

Expand All @@ -40,7 +40,12 @@ def test_get_distributed_client_empty_dask_file(mocker, tmp_path):
# TODO: Remove in v2.14.0
@pytest.mark.parametrize("use_new_dask_config", ["", "1"])
def test_force_new_dask_config(
monkeypatch, mocker, tmp_path, mock_dask_config_set, use_new_dask_config
monkeypatch,
mocker,
tmp_path,
mock_dask_config_set,
ignore_existing_user_config,
use_new_dask_config,
):
# Old config -> threaded scheduler
cfg_file = tmp_path / "dask.yml"
Expand Down Expand Up @@ -116,7 +121,7 @@ def test_get_old_dask_config(mocker, tmp_path):


def test_get_distributed_client_external(
monkeypatch, mocker, mock_dask_config_set
monkeypatch, mocker, mock_dask_config_set, ignore_existing_user_config
):
monkeypatch.setitem(
CFG,
Expand Down Expand Up @@ -188,7 +193,11 @@ def test_get_distributed_client_external_old(

@pytest.mark.parametrize("shutdown_timeout", [False, True])
def test_get_distributed_client_slurm(
monkeypatch, mocker, mock_dask_config_set, shutdown_timeout
monkeypatch,
mocker,
mock_dask_config_set,
ignore_existing_user_config,
shutdown_timeout,
):
slurm_cluster = {
"type": "dask_jobqueue.SLURMCluster",
Expand Down Expand Up @@ -292,7 +301,11 @@ def test_get_distributed_client_slurm_old(
)


def test_custom_default_scheduler(monkeypatch, mock_dask_config_set):
def test_custom_default_scheduler(
monkeypatch,
mock_dask_config_set,
ignore_existing_user_config,
):
default_scheduler = {"num_workers": 42, "scheduler": "processes"}
monkeypatch.setitem(
CFG,
Expand All @@ -306,7 +319,7 @@ def test_custom_default_scheduler(monkeypatch, mock_dask_config_set):
with _dask.get_distributed_client() as client:
assert client is None

mock_dask_config_set.assert_called_once_with(
mock_dask_config_set.assert_called_with(
{"num_workers": 42, "scheduler": "processes"}
)

Expand Down

0 comments on commit 85526a8

Please sign in to comment.