Skip to content

Commit 72514ac

Browse files
committed
allow imports outside of cwd
1 parent 4d524b6 commit 72514ac

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

airbyte_cdk/test/standard_tests/connector_base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import abc
77
import importlib
88
import inspect
9+
import os
910
import sys
1011
from collections.abc import Callable
1112
from pathlib import Path
@@ -43,18 +44,24 @@ def connector(cls) -> type[IConnector] | Callable[[], IConnector] | None:
4344
specific connector class to be tested.
4445
"""
4546
connector_root = cls.get_connector_root_dir()
46-
connector_name = connector_root.name
47+
connector_name = connector_root.absolute().name
4748

4849
expected_module_name = connector_name.replace("-", "_").lower()
4950
expected_class_name = connector_name.replace("-", "_").title().replace("_", "")
5051

5152
# dynamically import and get the connector class: <expected_module_name>.<expected_class_name>
5253

54+
cwd_snapshot = Path().absolute()
55+
os.chdir(connector_root)
56+
5357
# Dynamically import the module
5458
try:
5559
module = importlib.import_module(expected_module_name)
5660
except ModuleNotFoundError as e:
5761
raise ImportError(f"Could not import module '{expected_module_name}'.") from e
62+
finally:
63+
# Change back to the original working directory
64+
os.chdir(cwd_snapshot)
5865

5966
# Dynamically get the class from the module
6067
try:

0 commit comments

Comments
 (0)