From 52802e648cc1b97de5abfdbefcb8764445a9ff7b Mon Sep 17 00:00:00 2001 From: "Edgar R. M" Date: Fri, 21 Jul 2023 14:40:50 -0600 Subject: [PATCH] fix: Add deprecation warning when importing legacy testing helpers (#1838) * fix: Add deprecation warning when import legacy testing helpers * Document deprecation * Fix names * Test missing module attributes --- docs/deprecation.md | 2 ++ singer_sdk/testing/__init__.py | 38 ++++++++++++++++++++++++++++++---- tests/core/test_testing.py | 21 +++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 tests/core/test_testing.py diff --git a/docs/deprecation.md b/docs/deprecation.md index 089355fd9..b27e61b2b 100644 --- a/docs/deprecation.md +++ b/docs/deprecation.md @@ -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. diff --git a/singer_sdk/testing/__init__.py b/singer_sdk/testing/__init__.py index 24ce4ac9f..83ca9aacc 100644 --- a/singer_sdk/testing/__init__.py +++ b/singer_sdk/testing/__init__.py @@ -2,13 +2,14 @@ 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, @@ -16,13 +17,42 @@ ) 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", diff --git a/tests/core/test_testing.py b/tests/core/test_testing.py new file mode 100644 index 000000000..02672d9ad --- /dev/null +++ b/tests/core/test_testing.py @@ -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