Cleanup model ref resetting.

This commit is contained in:
Steve Pulec 2019-07-10 21:16:11 -05:00
parent 308712841c
commit b19c201975
3 changed files with 7 additions and 2 deletions

View File

@ -466,10 +466,14 @@ class BaseModel(object):
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__()

View File

@ -379,6 +379,7 @@ class SQSBackend(BaseBackend):
def reset(self):
region_name = self.region_name
self._reset_model_refs()
self.__dict__ = {}
self.__init__(region_name)

View File

@ -2,7 +2,7 @@ import sure # noqa
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")