From 5ac5f92839a410b2a6fd0d97e33c0d6537d04207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Thu, 13 Jul 2023 19:28:11 -0600 Subject: [PATCH 1/4] fix: Add deprecation warning when import legacy testing helpers --- singer_sdk/testing/__init__.py | 38 ++++++++++++++++++++++++++++++---- tests/core/test_testing.py | 13 ++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 tests/core/test_testing.py 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..afc4420cf --- /dev/null +++ b/tests/core/test_testing.py @@ -0,0 +1,13 @@ +"""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 0f54fd36ad4f20350f9f52eb0d0d9787ec056073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Thu, 13 Jul 2023 19:32:35 -0600 Subject: [PATCH 2/4] Document deprecation --- docs/deprecation.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/deprecation.md b/docs/deprecation.md index 089355fd9..8ba2f7dfb 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_standard_tap_target_tests` and `singer_sdk.testing.get_standard_tap_target_tests` functions respective to generate a richer test suite. From e5e8eb23dad4c694f64de9533ae185a64b07778b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Thu, 13 Jul 2023 19:35:09 -0600 Subject: [PATCH 3/4] Fix names --- docs/deprecation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/deprecation.md b/docs/deprecation.md index 8ba2f7dfb..b27e61b2b 100644 --- a/docs/deprecation.md +++ b/docs/deprecation.md @@ -12,4 +12,4 @@ incompatible way, following their deprecation, as indicated in the 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_standard_tap_target_tests` and `singer_sdk.testing.get_standard_tap_target_tests` functions respective to generate a richer test suite. +- 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. From 8cef53cf2e237d5278446c1105ddff29cbaa5a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Thu, 13 Jul 2023 19:44:58 -0600 Subject: [PATCH 4/4] Test missing module attributes --- tests/core/test_testing.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/core/test_testing.py b/tests/core/test_testing.py index afc4420cf..02672d9ad 100644 --- a/tests/core/test_testing.py +++ b/tests/core/test_testing.py @@ -11,3 +11,11 @@ def test_module_deprecations(): 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