diff options
author | Tim Graham <timograham@gmail.com> | 2016-09-14 14:25:09 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2016-09-14 19:43:36 -0400 |
commit | 029426fdd4afce3ec7bda33fe1c43059c73cdd79 (patch) | |
tree | f43257d4fcbe31850f69c162d33eb93b8288d06e | |
parent | f9702977b72003c17db87d6e4fdaa36415f13a38 (diff) | |
download | django-fix-cache-test.tar.gz |
Isolated test_close() cache test.fix-cache-test
-rw-r--r-- | tests/cache/tests.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 4bd882e791..7ae39278fd 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -21,7 +21,7 @@ from django.core.cache import ( DEFAULT_CACHE_ALIAS, CacheKeyWarning, cache, caches, ) from django.core.cache.utils import make_template_fragment_key -from django.db import connection, connections +from django.db import close_old_connections, connection, connections from django.http import ( HttpRequest, HttpResponse, HttpResponseNotModified, StreamingHttpResponse, ) @@ -1248,9 +1248,13 @@ class BaseMemcachedTests(BaseCacheTests): def test_close(self): # For clients that don't manage their connections properly, the # connection is closed when the request is complete. - with mock.patch.object(cache._lib.Client, 'disconnect_all', autospec=True) as mock_disconnect: - signals.request_finished.send(self.__class__) - self.assertIs(mock_disconnect.called, self.should_disconnect_on_close) + signals.request_finished.disconnect(close_old_connections) + try: + with mock.patch.object(cache._lib.Client, 'disconnect_all', autospec=True) as mock_disconnect: + signals.request_finished.send(self.__class__) + self.assertIs(mock_disconnect.called, self.should_disconnect_on_close) + finally: + signals.request_finished.connect(close_old_connections) @unittest.skipUnless(MemcachedCache_params, "MemcachedCache backend not configured") |