Skip to content

Commit

Permalink
Document using -W with pytest to detect deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Dec 23, 2022
1 parent 464cbff commit 608c0cc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/development/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ SemVer makes it easier to see at a glance how compatible releases are with each
## Deprecation policy

A [feature release](#feature-releases) may deprecate a feature, but it will not remove it until the next major release. A deprecation will be clearly documented in the changelog and in the code.

All deprecated features will emit a `SingerDeprecationWarning` when used, so users can raise them as exceptions when running their tests to ensure that they are not using any deprecated features:

```console
$ pytest -W error::singer_sdk.utils.deprecation.SingerSDKDeprecationWarning
```
6 changes: 5 additions & 1 deletion singer_sdk/streams/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)
from singer_sdk.plugin_base import PluginBase as TapBaseClass
from singer_sdk.streams.core import Stream
from singer_sdk.utils.deprecation import SingerSDKDeprecationWarning

if TYPE_CHECKING:
from backoff.types import Details
Expand Down Expand Up @@ -484,7 +485,7 @@ def get_new_paginator(self) -> BaseAPIPaginator:
A paginator instance.
"""
if hasattr(self, "get_next_page_token"):
warning = DeprecationWarning(
warning = SingerSDKDeprecationWarning(
"`RESTStream.get_next_page_token` is deprecated and will not be used "
+ "in a future version of the Meltano Singer SDK. "
+ "Override `RESTStream.get_new_paginator` instead."
Expand Down Expand Up @@ -535,13 +536,16 @@ def get_records(self, context: dict | None) -> Iterable[dict[str, Any]]:
Yields:
One item per (possibly processed) record in the API.
"""
# warn(SingerSDKDeprecationWarning("Use `request_records` instead."))
for record in self.request_records(context):
transformed_record = self.post_process(record, context)
if transformed_record is None:
# Record filtered out during post_process()
continue
yield transformed_record

self.requests_session.close()

def parse_response(self, response: requests.Response) -> Iterable[dict]:
"""Parse the response and return an iterator of result records.
Expand Down
1 change: 1 addition & 0 deletions singer_sdk/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Helpers for internal development of the Singer SDK."""
7 changes: 7 additions & 0 deletions singer_sdk/utils/deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Utilities for deprecating features."""

__all__ = ["SingerSDKDeprecationWarning"]


class SingerSDKDeprecationWarning(DeprecationWarning):
"""Warning to raise when a deprecated feature is used."""
3 changes: 2 additions & 1 deletion tests/core/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Property,
StringType,
)
from singer_sdk.utils.deprecation import SingerSDKDeprecationWarning

CONFIG_START_DATE = "2021-01-01"

Expand Down Expand Up @@ -461,7 +462,7 @@ def test_next_page_token_jsonpath(
RestTestStream.next_page_token_jsonpath = path
stream = RestTestStream(tap)

with pytest.warns(DeprecationWarning):
with pytest.warns(SingerSDKDeprecationWarning):
paginator = stream.get_new_paginator()

next_page = paginator.get_next(fake_response)
Expand Down

0 comments on commit 608c0cc

Please sign in to comment.