Skip to content

Commit

Permalink
Cleanup model ref resetting.
Browse files Browse the repository at this point in the history
  • Loading branch information
spulec committed Jul 11, 2019
1 parent 3087128 commit b19c201
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion moto/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()

Expand Down
1 change: 1 addition & 0 deletions moto/sqs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_core/test_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b19c201

Please sign in to comment.