Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Set Stream._MAX_RECORDS_LIMIT during tap testing #1399

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion singer_sdk/streams/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ def _sync_records(
)
raise ex

self._check_max_record_limit(record_count)
self._check_max_record_limit(partition_record_count)

if selected:
if (
Expand Down
2 changes: 2 additions & 0 deletions singer_sdk/testing/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class SuiteConfig:
"""Test Suite Config, passed to each test.

Args:
max_records_limit: Max records to fetch during tap testing.
ignore_no_records: Ignore stream test failures if stream returns no records,
for all streams.
ignore_no_records_for_streams: Ignore stream test failures if stream returns
no records, for named streams.
"""

max_records_limit: int | None = None
ignore_no_records: bool = False
ignore_no_records_for_streams: list[str] = field(default_factory=list)
12 changes: 6 additions & 6 deletions singer_sdk/testing/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def get_test_class(
Returns:
A test class usable by pytest.
"""
suite_config = suite_config or SuiteConfig()

class BaseTestClass:
"""Base test class."""
Expand Down Expand Up @@ -188,10 +187,13 @@ def get_tap_test_class(
if "parse_env_config" not in kwargs:
kwargs["parse_env_config"] = True

suite_config = suite_config or SuiteConfig()

return get_test_class(
test_runner=TapTestRunner(tap_class=tap_class, config=config, **kwargs),
test_runner=TapTestRunner(
tap_class=tap_class,
config=config,
suite_config=suite_config,
**kwargs,
),
test_suites=suites,
suite_config=suite_config,
)
Expand Down Expand Up @@ -224,8 +226,6 @@ def get_target_test_class(
if "parse_env_config" not in kwargs:
kwargs["parse_env_config"] = True

suite_config = suite_config or SuiteConfig()

return get_test_class(
test_runner=TargetTestRunner(
target_class=target_class,
Expand Down
7 changes: 6 additions & 1 deletion singer_sdk/testing/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ def tap(self) -> Tap:
Returns:
A configured Tap instance.
"""
return cast(Tap, self.create())
new_tap = cast(Tap, self.create())
# apply max_records_limit if set
if self.suite_config.max_records_limit is not None:
for stream in new_tap.streams.values():
stream._MAX_RECORDS_LIMIT = self.suite_config.max_records_limit
return new_tap

def run_discovery(self) -> str:
"""Run tap discovery.
Expand Down