Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly set the environment defaults in settings.py #3326

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion kedro/framework/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,16 @@ def _get_config_loader(self) -> AbstractConfigLoader:
extra_params = self.store.get("extra_params")

config_loader_class = settings.CONFIG_LOADER_CLASS
config_loader_args = settings.CONFIG_LOADER_ARGS
if not (
"base_env" in config_loader_args or "default_run_env" in config_loader_args
):
config_loader_args.update({"base_env": "base", "default_run_env": "local"})
merelcht marked this conversation as resolved.
Show resolved Hide resolved
return config_loader_class(
conf_source=self._conf_source,
env=env,
runtime_params=extra_params,
**settings.CONFIG_LOADER_ARGS,
**config_loader_args,
)

def close(self):
Expand Down
33 changes: 33 additions & 0 deletions tests/framework/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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_dont_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 == "base"
assert result.default_run_env == "local"

@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 "
Expand Down