Repository: kedro-org/kedro
File: tests/config/test_omegaconf_config.py (Python)

Code before:
    def test_no_files_found(self, tmp_path):
        """Check the error if no config files satisfy a given pattern"""
        pattern = (
            r"No files of YAML or JSON format found in "
            r".*base or "
            r".*local "
            r"matching the glob pattern\(s\): "
            r"\[\'credentials\*\', \'credentials\*/\**\', \'\**/credentials\*\'\]"
        )
        with pytest.raises(MissingConfigException, match=pattern):
            OmegaConfigLoader(
                str(tmp_path), base_env=_BASE_ENV, default_run_env=_DEFAULT_RUN_ENV
            )["credentials"]

    def test_empty_catalog_file(self, tmp_path):
        """Check that empty catalog file is read and returns an empty dict"""
        _write_yaml(tmp_path / _BASE_ENV / "catalog_empty.yml", {})
        catalog_patterns = {"catalog": ["catalog*", "catalog*/**", "**/catalog*"]}
        catalog = OmegaConfigLoader(
            conf_source=tmp_path, env="base", config_patterns=catalog_patterns
        )["catalog"]
        assert catalog == {}

    @pytest.mark.xfail(reason="Logic failing")
    def test_overlapping_patterns(self, tmp_path, mocker):
        """Check that same configuration file is not loaded more than once."""
        _write_yaml(
            tmp_path / _BASE_ENV / "catalog0.yml",
            {"env": _BASE_ENV, "common": "common"},
        )
        _write_yaml(
            tmp_path / "dev" / "catalog1.yml", {"env": "dev", "dev_specific": "wiz"}
        )
        _write_yaml(tmp_path / "dev" / "user1" / "catalog2.yml", {"user1_c2": True})

        catalog_patterns = {
            "catalog": [
                "catalog*",
                "catalog*/**",
                "../**/user1/catalog2*",
                "../**/catalog2*",
            ]
        }

        # Use a mocked function to keep track of function calls
        with mocker.patch(
            "omegaconf.OmegaConf.load", wraps=OmegaConf.load
        ) as mocked_load:
            catalog = OmegaConfigLoader(
                conf_source=str(tmp_path),
                base_env=_BASE_ENV,

Review comment (bug):
Fixed the test to check for the intended behaviour. However, it fails, and manual testing shows that this is due to the implementation of the OmegaConfigLoader. I would suggest correcting this should be split out into a separate issue to be addressed.

Code after:

    @use_config_dir
    def test_no_files_found(self, tmp_path):
        """Check the error if no config files satisfy a given pattern"""
        pattern = (
            r"No files of YAML or JSON format found in "
            r".*base or "
            r".*local "
            r"matching the glob pattern\(s\): "
            r"\[\'credentials\*\', \'credentials\*/\**\', \'\**/credentials\*\'\]"
        )
        with pytest.raises(MissingConfigException, match=pattern):
            OmegaConfigLoader(
                str(tmp_path), base_env=_BASE_ENV, default_run_env=_DEFAULT_RUN_ENV
            )["credentials"]

    def test_empty_catalog_file(self, tmp_path):
        """Check that empty catalog file is read and returns an empty dict"""
        _write_yaml(tmp_path / _BASE_ENV / "catalog_empty.yml", {})
        catalog_patterns = {"catalog": ["catalog*", "catalog*/**", "**/catalog*"]}
        catalog = OmegaConfigLoader(
            conf_source=tmp_path, env="base", config_patterns=catalog_patterns
        )["catalog"]
        assert catalog == {}

    @pytest.mark.xfail(reason="Logic failing")
    def test_overlapping_patterns(self, tmp_path, mocker):
        """Check that same configuration file is not loaded more than once."""
        _write_yaml(
            tmp_path / _BASE_ENV / "catalog0.yml",
            {"env": _BASE_ENV, "common": "common"},
        )
        _write_yaml(
            tmp_path / "dev" / "catalog1.yml", {"env": "dev", "dev_specific": "wiz"}
        )
        _write_yaml(tmp_path / "dev" / "user1" / "catalog2.yml", {"user1_c2": True})

        catalog_patterns = {
            "catalog": [
                "catalog*",
                "catalog*/**",
                "../**/user1/catalog2*",
                "../**/catalog2*",
            ]
        }

        load_spy = mocker.spy(OmegaConf, "load")
        catalog = OmegaConfigLoader(
            conf_source=str(tmp_path),
            base_env=_BASE_ENV,
            env="dev",