From f3fbce7e082d0b13cb1ba7dc9296b6c506a781ac Mon Sep 17 00:00:00 2001 From: Merel Theisen <49397448+merelcht@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:05:11 +0000 Subject: [PATCH] Explicitly set the environment defaults in `settings.py` (#3326) Signed-off-by: Merel Theisen --- .../settings.py | 8 ++--- .../settings.py | 8 ++--- tests/framework/session/test_session.py | 33 +++++++++++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/features/steps/test_starter/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/settings.py b/features/steps/test_starter/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/settings.py index 3207b1da0a..5967eda35e 100644 --- a/features/steps/test_starter/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/settings.py +++ b/features/steps/test_starter/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/settings.py @@ -25,14 +25,14 @@ # from kedro.config import OmegaConfigLoader # CONFIG_LOADER_CLASS = OmegaConfigLoader # Keyword arguments to pass to the `CONFIG_LOADER_CLASS` constructor. -# CONFIG_LOADER_ARGS = { -# "base_env": "base", -# "default_run_env": "local", +CONFIG_LOADER_ARGS = { + "base_env": "base", + "default_run_env": "local", # "config_patterns": { # "spark" : ["spark*/"], # "parameters": ["parameters*", "parameters*/**", "**/parameters*"], # } -# } +} # Class that manages Kedro's library components. # from kedro.framework.context import KedroContext diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/settings.py b/kedro/templates/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/settings.py index db58cab52d..59a60aa905 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/settings.py +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/src/{{ cookiecutter.python_package }}/settings.py @@ -28,14 +28,14 @@ # CONFIG_LOADER_CLASS = OmegaConfigLoader # Keyword arguments to pass to the `CONFIG_LOADER_CLASS` constructor. -# CONFIG_LOADER_ARGS = { -# "base_env": "base", -# "default_run_env": "local", +CONFIG_LOADER_ARGS = { + "base_env": "base", + "default_run_env": "local", # "config_patterns": { # "spark" : ["spark*/"], # "parameters": ["parameters*", "parameters*/**", "**/parameters*"], # } -# } +} # Class that manages Kedro's library components. # from kedro.framework.context import KedroContext diff --git a/tests/framework/session/test_session.py b/tests/framework/session/test_session.py index 9e4e9364a5..532d42259d 100644 --- a/tests/framework/session/test_session.py +++ b/tests/framework/session/test_session.py @@ -165,6 +165,17 @@ class MockSettings(_ProjectSettings): return _mock_imported_settings_paths(mocker, MockSettings()) +@pytest.fixture +def mock_settings_config_loader_args_env(mocker): + class MockSettings(_ProjectSettings): + _CONFIG_LOADER_ARGS = Validator( + "CONFIG_LOADER_ARGS", + default={"base_env": "something_new"}, + ) + + return _mock_imported_settings_paths(mocker, MockSettings()) + + @pytest.fixture def mock_settings_file_bad_config_loader_class(tmpdir): mock_settings_file = tmpdir.join("mock_settings_file.py") @@ -423,6 +434,28 @@ def test_load_config_loader_args(self, fake_project, mock_package_name, mocker): ) assert result["spark"] == ["spark/*"] + @pytest.mark.usefixtures("mock_settings_config_loader_args") + def test_config_loader_args_no_env_overwrites_env( + self, fake_project, mock_package_name, mocker + ): + session = KedroSession.create(mock_package_name, fake_project) + result = session._get_config_loader() + + assert isinstance(result, OmegaConfigLoader) + assert result.base_env == "" + assert result.default_run_env == "" + + @pytest.mark.usefixtures("mock_settings_config_loader_args_env") + def test_config_loader_args_overwrite_env( + self, fake_project, mock_package_name, mocker + ): + session = KedroSession.create(mock_package_name, fake_project) + result = session._get_config_loader() + + assert isinstance(result, OmegaConfigLoader) + assert result.base_env == "something_new" + assert result.default_run_env == "" + def test_broken_config_loader(self, mock_settings_file_bad_config_loader_class): pattern = ( "Invalid value 'tests.framework.session.test_session.BadConfigLoader' received "