Skip to content

Commit 1278da1

Browse files
feat: add empty_streams filtering to standard test suites
- Add EmptyStreamConfig model and empty_streams field to ConnectorTestScenario - Extend get_scenarios() to include basic_read category - Implement catalog filtering in test_basic_read and test_docker_image_build_and_read methods - Exclude streams declared as empty_streams from test execution to prevent failures in sandbox environments Co-Authored-By: AJ Steers <[email protected]>
1 parent cc93e62 commit 1278da1

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

airbyte_cdk/test/models/scenario.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
from collections.abc import Generator
2525

2626

27+
class EmptyStreamConfig(BaseModel):
28+
"""Configuration for streams that should be excluded from tests."""
29+
30+
name: str
31+
bypass_reason: str
32+
33+
2734
class ConnectorTestScenario(BaseModel):
2835
"""Acceptance test scenario, as a Pydantic model.
2936
@@ -50,6 +57,7 @@ class AcceptanceTestFileTypes(BaseModel):
5057
_id: str | None = None # Used to override the default ID generation
5158

5259
configured_catalog_path: Path | None = None
60+
empty_streams: list[EmptyStreamConfig] | None = None
5361
timeout_seconds: int | None = None
5462
expect_records: AcceptanceTestExpectRecords | None = None
5563
file_types: AcceptanceTestFileTypes | None = None

airbyte_cdk/test/standard_tests/docker_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def get_scenarios(
7373
This has to be a separate function because pytest does not allow
7474
parametrization of fixtures with arguments from the test class itself.
7575
"""
76-
categories = ["connection", "spec"]
76+
categories = ["connection", "spec", "basic_read"]
7777
try:
7878
acceptance_test_config_path = cls.acceptance_test_config_path
7979
except FileNotFoundError as e:
@@ -336,6 +336,10 @@ def test_docker_image_build_and_read(
336336
# If `read_from_streams` is a list, we filter the discovered streams.
337337
streams_list = list(set(streams_list) & set(read_from_streams))
338338

339+
if scenario.empty_streams:
340+
streams_to_exclude = {empty_stream.name for empty_stream in scenario.empty_streams}
341+
streams_list = [stream for stream in streams_list if stream not in streams_to_exclude]
342+
339343
configured_catalog: ConfiguredAirbyteCatalog = ConfiguredAirbyteCatalog(
340344
streams=[
341345
ConfiguredAirbyteStream(

airbyte_cdk/test/standard_tests/source_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ def test_basic_read(
121121
# Failed as expected; we're done.
122122
return
123123

124+
streams_to_exclude = set()
125+
if scenario.empty_streams:
126+
streams_to_exclude = {empty_stream.name for empty_stream in scenario.empty_streams}
127+
124128
configured_catalog = ConfiguredAirbyteCatalog(
125129
streams=[
126130
ConfiguredAirbyteStream(
@@ -129,6 +133,7 @@ def test_basic_read(
129133
destination_sync_mode=DestinationSyncMode.append_dedup,
130134
)
131135
for stream in discover_result.catalog.catalog.streams # type: ignore [reportOptionalMemberAccess, union-attr]
136+
if stream.name not in streams_to_exclude
132137
]
133138
)
134139
result = run_test_job(

0 commit comments

Comments
 (0)