:question: Is there an extra step required to run ...
# questions
r
Is there an extra step required to run Pytest with interpolated variables in the parameters (from
globals.yml
)? The error is
Copy code
omegaconf.errors.InterpolationResolutionError: Globals key 'dim_product_filepath' not found and no default value provided.
My set up is:
Copy code
#conf/base/globals.yml
dim_product_filepath: "data/01_raw/dim_product.parquet"
Clearly
dim_product_filepath
is in
globals.yml
Copy code
#conf/base/catalog.yml
dim_product:
  type: pandas.ParquetDataset
  filepath: ${globals:dim_product_filepath}
Copy code
#conf/base/parameters.yml
dim_product_filepath: ${globals:dim_product_filepath}
Strangely, running the node works with no problem.
Copy code
#src/my_project/pipelines/data_processing/pipeline.py
def create_pipeline(**kwargs) -> Pipeline:
    return pipeline(
        [
            node(
                func=load_dim_product,
                inputs=[
                    "params:dim_product_sql",
                    "params:project_id",
                    "params:dim_product_filepath",
                    "params:env",
                ],
                outputs="dim_product",
                name="load_dim_product",
            ),
            ...,
        ]
    )
n
Hi @Roger Yu, have you read this already? https://docs.kedro.org/en/stable/tutorial/test_a_project.html. It's ususally advised to create the Kedro class directly for testing, i.e.
DataCatalog
OmegaConfigLoader
. These components need to know where is your root directory. when you do
kedro run
we automatically figure it out for you, when you put them in
pytest
, you may need to specific the location otherwise it's looking ifor config in the wrong place.
The above example should helps
^ I do notice the link I shared above is a bit hard to search, opened an issue to link this in the "Testing Kedro project" category properly.
r
> https://docs.kedro.org/en/stable/tutorial/test_a_project.html I just read this. 1. There's no mention of
OmegaConfigLoader
2. The example with
DataCatalog
hardcodes the catalog keys/values and parameter keys/values. Is this what's expected in unit testing in Kedro? e.g.
Copy code
catalog.add_feed_dict(
            {
                "model_input_table" : dummy_data,
                "params:model_options": dummy_parameters["model_options"],
            }
        )
3. There's no example of telling Pytest how to address the
globals.yml
. Is there another page that explains this?
n
@Roger Yu Sorry for the late reply. I thought the documentation mentions it but it was my mistake. I raised an issue regarding to the default test example. In short, you can create the config loader as follow:
Copy code
@pytest.fixture
def config_loader():
    return OmegaConfigLoader(conf_source="conf",base_env="base", default_run_env="local")
I cannot find one specific section answering your questions, but there are few concept that are related to this in https://docs.kedro.org/en/stable/configuration/configuration_basics.html#omegaconfigloader 1.
base_env
and
default_run_env
need to be set correctly when you create
OmegaConfigLoader
manually. This isn't needed when you do
kedro run
because the framework will read
settings.py
and apply the default automatically. The reason for this is that we expect people to use
ConfigLoader
outside of framework (decoupled). 2. ^This is related to globals, because the config loader need to know where to locate the config files, the reason why your previous test fail to locate the file is because the
conf_source
and env is set incorrectly. The config loader use default config_pattern (customisable)
👍 1
It would be great if you can let me know the snippet above works, I will discuss with the team how should we address the example
r
Yes, that worked thank you!
👍🏼 1