Skip to content

Commit

Permalink
fix: Add deprecation warning when importing legacy testing helpers (#…
Browse files Browse the repository at this point in the history
…1838)

* fix: Add deprecation warning when import legacy testing helpers

* Document deprecation

* Fix names

* Test missing module attributes
  • Loading branch information
edgarrmondragon authored Jul 21, 2023
1 parent c444601 commit 52802e6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/deprecation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ incompatible way, following their deprecation, as indicated in the
[`RESTStream.get_new_paginator`](singer_sdk.RESTStream.get_new_paginator).

See the [migration guide](./guides/pagination-classes.md) for more information.

- The `singer_sdk.testing.get_standard_tap_tests` and `singer_sdk.testing.get_standard_target_tests` functions will be removed. Replace them with `singer_sdk.testing.get_tap_test_class` and `singer_sdk.testing.get_target_test_class` functions respective to generate a richer test suite.
38 changes: 34 additions & 4 deletions singer_sdk/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,57 @@

from __future__ import annotations

import typing as t
import warnings

from .config import SuiteConfig
from .factory import get_tap_test_class, get_target_test_class
from .legacy import (
_get_tap_catalog,
_select_all,
get_standard_tap_tests,
get_standard_target_tests,
sync_end_to_end,
tap_sync_test,
tap_to_target_sync_test,
target_sync_test,
)
from .runners import SingerTestRunner, TapTestRunner, TargetTestRunner


def __getattr__(name: str) -> t.Any: # noqa: ANN401
if name == "get_standard_tap_tests":
warnings.warn(
"The function singer_sdk.testing.get_standard_tap_tests is deprecated "
"and will be removed in a future release. Use get_tap_test_class instead.",
DeprecationWarning,
stacklevel=2,
)

from .legacy import get_standard_tap_tests

return get_standard_tap_tests

if name == "get_standard_target_tests":
warnings.warn(
"The function singer_sdk.testing.get_standard_target_tests is deprecated "
"and will be removed in a future release. Use get_target_test_class "
"instead.",
DeprecationWarning,
stacklevel=2,
)

from .legacy import get_standard_target_tests

return get_standard_target_tests

msg = f"module {__name__} has no attribute {name}"
raise AttributeError(msg)


__all__ = [
"get_tap_test_class",
"get_target_test_class",
"_get_tap_catalog",
"_select_all",
"get_standard_tap_tests",
"get_standard_target_tests",
"sync_end_to_end",
"tap_sync_test",
"tap_to_target_sync_test",
Expand Down
21 changes: 21 additions & 0 deletions tests/core/test_testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Test the plugin testing helpers."""

from __future__ import annotations

import pytest


def test_module_deprecations():
with pytest.deprecated_call():
from singer_sdk.testing import get_standard_tap_tests # noqa: F401

with pytest.deprecated_call():
from singer_sdk.testing import get_standard_target_tests # noqa: F401

from singer_sdk import testing

with pytest.raises(
AttributeError,
match="module singer_sdk.testing has no attribute",
):
testing.foo # noqa: B018

0 comments on commit 52802e6

Please sign in to comment.