From ab531aed9bcb64ce41069040d56a633fe7dcac47 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Thu, 4 Nov 2021 21:39:53 -0100 Subject: [PATCH] Add warnings about deprecated modules (#4527) --- moto/__init__.py | 15 ++++++++++++--- tests/test_dynamodb/test_dynamodb.py | 10 +++++++++- tests/test_rds/test_rds.py | 9 +++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/moto/__init__.py b/moto/__init__.py index 7b789af79..3747e5038 100644 --- a/moto/__init__.py +++ b/moto/__init__.py @@ -1,8 +1,17 @@ import importlib -def lazy_load(module_name, element, boto3_name=None, backend=None): +def lazy_load( + module_name, element, boto3_name=None, backend=None, warn_repurpose=False +): def f(*args, **kwargs): + if warn_repurpose: + import warnings + + warnings.warn( + f"Module {element} has been deprecated, and will be repurposed in a later release. " + "Please see https://github.com/spulec/moto/issues/4526 for more information." + ) module = importlib.import_module(module_name, "moto") return getattr(module, element)(*args, **kwargs) @@ -53,7 +62,7 @@ mock_datapipeline_deprecated = lazy_load( mock_datasync = lazy_load(".datasync", "mock_datasync") mock_dms = lazy_load(".dms", "mock_dms") mock_ds = lazy_load(".ds", "mock_ds", boto3_name="ds") -mock_dynamodb = lazy_load(".dynamodb", "mock_dynamodb") +mock_dynamodb = lazy_load(".dynamodb", "mock_dynamodb", warn_repurpose=True) mock_dynamodb_deprecated = lazy_load(".dynamodb", "mock_dynamodb_deprecated") mock_dynamodb2 = lazy_load(".dynamodb2", "mock_dynamodb2", backend="dynamodb_backends2") mock_dynamodb2_deprecated = lazy_load(".dynamodb2", "mock_dynamodb2_deprecated") @@ -99,7 +108,7 @@ mock_opsworks_deprecated = lazy_load(".opsworks", "mock_opsworks_deprecated") mock_organizations = lazy_load(".organizations", "mock_organizations") mock_polly = lazy_load(".polly", "mock_polly") mock_ram = lazy_load(".ram", "mock_ram") -mock_rds = lazy_load(".rds", "mock_rds") +mock_rds = lazy_load(".rds", "mock_rds", warn_repurpose=True) mock_rds_deprecated = lazy_load(".rds", "mock_rds_deprecated") mock_rds2 = lazy_load(".rds2", "mock_rds2", boto3_name="rds") mock_rds2_deprecated = lazy_load(".rds2", "mock_rds2_deprecated") diff --git a/tests/test_dynamodb/test_dynamodb.py b/tests/test_dynamodb/test_dynamodb.py index 2f0874689..7a36446be 100644 --- a/tests/test_dynamodb/test_dynamodb.py +++ b/tests/test_dynamodb/test_dynamodb.py @@ -3,12 +3,20 @@ import boto.dynamodb import sure # noqa # pylint: disable=unused-import import pytest -from moto import mock_dynamodb_deprecated +from moto import mock_dynamodb, mock_dynamodb_deprecated from moto.dynamodb import dynamodb_backend from boto.exception import DynamoDBResponseError +def test_deprecation_warning(): + with pytest.warns(None) as record: + mock_dynamodb() + str(record[0].message).should.contain( + "Module mock_dynamodb has been deprecated, and will be repurposed in a later release" + ) + + # Has boto3 equivalent @mock_dynamodb_deprecated def test_list_tables(): diff --git a/tests/test_rds/test_rds.py b/tests/test_rds/test_rds.py index 9f5abbba5..aa688af89 100644 --- a/tests/test_rds/test_rds.py +++ b/tests/test_rds/test_rds.py @@ -3,10 +3,19 @@ import boto.rds import boto.vpc from boto.exception import BotoServerError import sure # noqa # pylint: disable=unused-import +import pytest from moto import mock_ec2_deprecated, mock_rds_deprecated, mock_rds +def test_deprecation_warning(): + with pytest.warns(None) as record: + mock_rds() + str(record[0].message).should.contain( + "Module mock_rds has been deprecated, and will be repurposed in a later release" + ) + + @mock_rds_deprecated def test_create_database(): conn = boto.rds.connect_to_region("us-west-2")