Hi , I'm developing a custom dataset which uses cu...
# questions
r
Hi , I'm developing a custom dataset which uses custom hooks. Now I dont know how to unittest these hooks? My hook looks like class MetadataHooks: """Kedro hook implementations for metadata handling.""" def __init__(self) -> None: """Initializes the hook with default values.""" self._metadata: dict[str, Any] = {} self._manipulated_at = datetime.now(timezone.utc).isoformat() @hook_impl(tryfirst=True) def before_pipeline_run(self, catalog: CatalogProtocol[Any, Any]) -> None: """Attach the shared session to every Snowpark dataset in the catalog. Args: catalog: The data catalog, which contains all datasets. """ for name, dataset in catalog.items(): if isinstance(dataset, SnowparkTableDataset): metadata = dataset.metadata or {} dataset.metadata = {**metadata, "_manipulated_at": self._manipulated_at} logger.debug("Attached metadata %s to Snowpark datasets %s", self._metadata, name) I want to test whether the dataset contains the metadata after the hook got executed. How do I do that? I saw the page about the automated testing https://kedro1.readthedocs.io/en/0.19.0.post4/development/automated_testing.html but dont really get it. Thanks for your help
👀 1
i
https://docs.kedro.org/en/stable/develop/automated_testing/ This is the latest link for the page But I don't think it will help you You'll need to add some concepts to that page. Specifically, construct a testing catalog programatically: https://docs.kedro.org/en/stable/catalog-data/advanced_data_catalog_usage/ You can mock most of it since all you want to test is that the metadata gets applied properly. You should also patch
datetime.now
so that the test is reliable (https://docs.pytest.org/en/stable/how-to/monkeypatch.html)