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 all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
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_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 "
Expand Down