Skip to content

Commit

Permalink
fix: Fix tap tests for multiple test classes with different input cat…
Browse files Browse the repository at this point in the history
…alogs (#1913)

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

* Fix mro mess

* Test the test class mro
  • Loading branch information
edgarrmondragon authored Aug 17, 2023
1 parent c9eda5a commit 2e45606
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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}

0 comments on commit 2e45606

Please sign in to comment.