diff --git a/moto/core/models.py b/moto/core/models.py index 75a5ecce1e4..1b0f2d0ddf5 100644 --- a/moto/core/models.py +++ b/moto/core/models.py @@ -466,10 +466,14 @@ def __new__(cls, *args, **kwargs): class BaseBackend(object): - def reset(self): + def _reset_model_refs(self): + # Remove all references to the models stored for service, models in model_data.items(): for model_name, model in models.items(): model.instances = [] + + def reset(self): + self._reset_model_refs() self.__dict__ = {} self.__init__() diff --git a/moto/sqs/models.py b/moto/sqs/models.py index 1404ded757b..f2e3ed40088 100644 --- a/moto/sqs/models.py +++ b/moto/sqs/models.py @@ -379,6 +379,7 @@ def __init__(self, region_name): def reset(self): region_name = self.region_name + self._reset_model_refs() self.__dict__ = {} self.__init__(region_name) diff --git a/tests/test_core/test_context_manager.py b/tests/test_core/test_context_manager.py index c5a22558ff7..96d2bec9ac8 100644 --- a/tests/test_core/test_context_manager.py +++ b/tests/test_core/test_context_manager.py @@ -2,7 +2,7 @@ import boto3 from moto import mock_sqs -def test_reset_api(): +def test_context_manager_returns_mock(): with mock_sqs() as sqs_mock: conn = boto3.client("sqs", region_name='us-west-1') conn.create_queue(QueueName="queue1")