diff --git a/airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py b/airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py index f6e1cc0d6..fbdf3e0de 100644 --- a/airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py +++ b/airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py @@ -1405,7 +1405,19 @@ def _get_class_from_fully_qualified_class_name( try: module_ref = importlib.import_module(module_name_full) except ModuleNotFoundError as e: - raise ValueError(f"Could not load module `{module_name_full}`.") from e + if split[0] == "source_declarative_manifest": + # During testing, the modules containing the custom components are not moved to source_declarative_manifest. In order to run the test, add the source folder to your PYTHONPATH or add it runtime using sys.path.append + try: + import os + + module_name_with_source_declarative_manifest = ".".join(split[1:-1]) + module_ref = importlib.import_module( + module_name_with_source_declarative_manifest + ) + except ModuleNotFoundError: + raise ValueError(f"Could not load module `{module_name_full}`.") from e + else: + raise ValueError(f"Could not load module `{module_name_full}`.") from e try: return getattr(module_ref, class_name) diff --git a/airbyte_cdk/sources/declarative/yaml_declarative_source.py b/airbyte_cdk/sources/declarative/yaml_declarative_source.py index 04ccda4cf..a2a08f03b 100644 --- a/airbyte_cdk/sources/declarative/yaml_declarative_source.py +++ b/airbyte_cdk/sources/declarative/yaml_declarative_source.py @@ -39,13 +39,18 @@ def __init__( ) def _read_and_parse_yaml_file(self, path_to_yaml_file: str) -> ConnectionDefinition: - package = self.__class__.__module__.split(".")[0] + try: + # For testing purposes, we want to allow to just pass a file + with open(path_to_yaml_file, "r") as f: + return yaml.safe_load(f) # type: ignore # we assume the yaml represents a ConnectionDefinition + except FileNotFoundError: + # Running inside the container, the working directory during an operation is not structured the same as the static files + package = self.__class__.__module__.split(".")[0] - yaml_config = pkgutil.get_data(package, path_to_yaml_file) - if yaml_config: - decoded_yaml = yaml_config.decode() - return self._parse(decoded_yaml) - else: + yaml_config = pkgutil.get_data(package, path_to_yaml_file) + if yaml_config: + decoded_yaml = yaml_config.decode() + return self._parse(decoded_yaml) return {} def _emit_manifest_debug_message(self, extra_args: dict[str, Any]) -> None: