Skip to content

Commit e92f948

Browse files
committed
handle multiple scenarios with same config
1 parent b3752dd commit e92f948

File tree

1 file changed

+10
-55
lines changed

1 file changed

+10
-55
lines changed

airbyte_cdk/test/standard_tests/docker_base.py

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -82,58 +82,6 @@ def acceptance_test_config(cls) -> dict[str, object]:
8282
)
8383
return tests_config
8484

85-
86-
@classmethod
87-
def _get_empty_streams(cls) -> list[str]:
88-
"""Parse the acceptance test config file and return a list of stream names that are empty.
89-
90-
In reality, the "empty" designation could indicate the stream has no data or that reading from
91-
it could result in an error (e.g. our sandbox account doesn't not have access to that stream).
92-
93-
This method is used to tell the test suite to skip reading from those streams.
94-
"""
95-
try:
96-
all_tests_config = cls.acceptance_test_config
97-
except FileNotFoundError as e:
98-
# Destinations sometimes do not have an acceptance tests file.
99-
warnings.warn(
100-
f"Acceptance test config file not found: {e!s}. No streams will be skipped.",
101-
category=UserWarning,
102-
stacklevel=1,
103-
)
104-
return []
105-
106-
if "basic_read" not in all_tests_config["acceptance_tests"]:
107-
warnings.warn(
108-
"No 'basic_read' section found in acceptance test config. No streams will be skipped.",
109-
category=UserWarning,
110-
stacklevel=1,
111-
)
112-
return []
113-
basic_read_block = all_tests_config["acceptance_tests"]["basic_read"]
114-
115-
# there is some inconsistency in the acceptance test config file
116-
# sometimes tests are defined under "tests" key, sometimes directly under the "basic_read" key.
117-
# We will handle both cases.
118-
basic_read_scenarios = basic_read_block.get("tests", basic_read_block)
119-
if not isinstance(basic_read_scenarios, list) or len(basic_read_scenarios) == 0:
120-
warnings.warn(
121-
"No 'tests' key found in 'basic_read' section of acceptance test config. "
122-
"No streams will be skipped.",
123-
category=UserWarning,
124-
stacklevel=1,
125-
)
126-
return []
127-
128-
empty_streams: list[str] = []
129-
# Iterate through the scenarios and collect empty streams.
130-
for scenario in basic_read_scenarios:
131-
if "empty_streams" in scenario:
132-
# If the scenario has an "empty_streams" key, return its value.
133-
empty_streams.extend(scenario["empty_streams"]["name"])
134-
135-
return empty_streams
136-
13785
@classmethod
13886
def get_scenarios(
13987
cls,
@@ -143,7 +91,6 @@ def get_scenarios(
14391
This has to be a separate function because pytest does not allow
14492
parametrization of fixtures with arguments from the test class itself.
14593
"""
146-
categories = ["spec", "connection", "basic_read"]
14794
try:
14895
all_tests_config = cls.acceptance_test_config
14996
except FileNotFoundError as e:
@@ -156,7 +103,7 @@ def get_scenarios(
156103
return []
157104

158105
test_scenarios: list[ConnectorTestScenario] = []
159-
for category in categories:
106+
for category in ["spec", "connection", "basic_read"]:
160107
if (
161108
category not in all_tests_config["acceptance_tests"]
162109
or "tests" not in all_tests_config["acceptance_tests"][category]
@@ -177,10 +124,18 @@ def get_scenarios(
177124
test_scenarios.append(scenario)
178125

179126
# Remove duplicate scenarios based on config_path.
180-
deduped_test_scenarios = []
127+
deduped_test_scenarios: list[ConnectorTestScenario] = []
181128
for scenario in test_scenarios:
182129
for existing_scenario in deduped_test_scenarios:
183130
if scenario.config_path == existing_scenario.config_path:
131+
# If a scenario with the same config_path already exists, we merge the empty streams.
132+
# scenarios are immutable, so we create a new one.
133+
all_empty_streams = (existing_scenario.empty_streams or []) + (scenario.empty_streams or [])
134+
new_scenario = existing_scenario.model_copy(
135+
update={"empty_streams": all_empty_streams}
136+
)
137+
deduped_test_scenarios.remove(existing_scenario)
138+
deduped_test_scenarios.append(new_scenario)
184139
break
185140
else:
186141
# If a scenario does not exist with the config, add the new scenario to the list.

0 commit comments

Comments
 (0)