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

fix: Fix tap tests for multiple test classes with different input catalogs #1913

Merged
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
18 changes: 15 additions & 3 deletions singer_sdk/testing/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@
class BaseTestClass:
"""Base test class."""

params: t.ClassVar[dict] = {}
param_ids: t.ClassVar[dict] = {}
params: dict[str, t.Any]
param_ids: dict[str, list[str]]

def __init_subclass__(cls, **kwargs: t.Any) -> None:
"""Initialize a subclass.

Args:
**kwargs: Keyword arguments.
"""
# Add empty params and param_ids attributes to a direct subclass but not to
# subclasses of subclasses
if cls.__base__ == BaseTestClass:
cls.params = {}
cls.param_ids = {}


class TapTestClassFactory:
Expand Down Expand Up @@ -183,7 +195,7 @@ def _annotate_test_class( # noqa: C901
test = test_class()
test_name = f"test_{suite.kind}_{test.name}"
test_params = []
test_ids = []
test_ids: list[str] = []
for stream in streams:
test_params.extend(
[
Expand Down
22 changes: 22 additions & 0 deletions tests/core/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest

from singer_sdk.testing.factory import BaseTestClass


def test_module_deprecations():
with pytest.deprecated_call():
Expand All @@ -19,3 +21,23 @@ def test_module_deprecations():
match="module singer_sdk.testing has no attribute",
):
testing.foo # noqa: B018


def test_test_class_mro():
class PluginTestClass(BaseTestClass):
pass

PluginTestClass.params["x"] = 1

class AnotherPluginTestClass(BaseTestClass):
pass

AnotherPluginTestClass.params["x"] = 2
AnotherPluginTestClass.params["y"] = 3

class SubPluginTestClass(PluginTestClass):
pass

assert PluginTestClass.params == {"x": 1}
assert AnotherPluginTestClass.params == {"x": 2, "y": 3}
assert SubPluginTestClass.params == {"x": 1}