From ec0d8080108e8eeeecc33f50d5a44f509affde22 Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Wed, 11 Apr 2018 09:39:33 -0400 Subject: [PATCH] Only start responses patcher if not already activated. --- moto/core/models.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/moto/core/models.py b/moto/core/models.py index cc7b5d8f9..92dc2a980 100644 --- a/moto/core/models.py +++ b/moto/core/models.py @@ -172,21 +172,26 @@ class CallbackResponse(responses.CallbackResponse): botocore_mock = responses.RequestsMock(assert_all_requests_are_fired=False, target='botocore.vendored.requests.adapters.HTTPAdapter.send') +responses_mock = responses._default_mock class ResponsesMockAWS(BaseMockAWS): def reset(self): botocore_mock.reset() - responses.reset() + responses_mock.reset() def enable_patching(self): - botocore_mock.start() - responses.start() + if not hasattr(botocore_mock, '_patcher') or not hasattr(botocore_mock._patcher, 'target'): + # Check for unactivated patcher + botocore_mock.start() + + if not hasattr(responses_mock, '_patcher') or not hasattr(responses_mock._patcher, 'target'): + responses_mock.start() for method in RESPONSES_METHODS: for backend in self.backends_for_urls.values(): for key, value in backend.urls.items(): - responses.add( + responses_mock.add( CallbackResponse( method=method, url=re.compile(key), @@ -212,7 +217,7 @@ class ResponsesMockAWS(BaseMockAWS): pass try: - responses.stop() + responses_mock.stop() except RuntimeError: pass