diff --git a/django/test/client.py b/django/test/client.py
index 77d4de0..6bdc1cf 100644
a
|
b
|
from django.conf import settings
|
16 | 16 | from django.contrib.auth import authenticate, login |
17 | 17 | from django.core.handlers.base import BaseHandler |
18 | 18 | from django.core.handlers.wsgi import WSGIRequest |
19 | | from django.core.signals import got_request_exception |
| 19 | from django.core.signals import (request_started, request_finished, |
| 20 | got_request_exception) |
| 21 | from django.db import close_connection |
20 | 22 | from django.http import SimpleCookie, HttpRequest, QueryDict |
21 | 23 | from django.template import TemplateDoesNotExist |
22 | 24 | from django.test import signals |
… |
… |
def closing_iterator_wrapper(iterable, close):
|
76 | 78 | for item in iterable: |
77 | 79 | yield item |
78 | 80 | finally: |
79 | | close() |
| 81 | request_finished.disconnect(close_connection) |
| 82 | close() # will fire request_finished |
| 83 | request_finished.connect(close_connection) |
80 | 84 | |
81 | 85 | |
82 | 86 | class ClientHandler(BaseHandler): |
… |
… |
class ClientHandler(BaseHandler):
|
91 | 95 | |
92 | 96 | def __call__(self, environ): |
93 | 97 | from django.conf import settings |
94 | | from django.core import signals |
95 | 98 | |
96 | 99 | # Set up middleware if needed. We couldn't do this earlier, because |
97 | 100 | # settings weren't available. |
98 | 101 | if self._request_middleware is None: |
99 | 102 | self.load_middleware() |
100 | 103 | |
101 | | signals.request_started.send(sender=self.__class__) |
| 104 | request_started.send(sender=self.__class__) |
102 | 105 | request = WSGIRequest(environ) |
103 | 106 | # sneaky little hack so that we can easily get round |
104 | 107 | # CsrfViewMiddleware. This makes life easier, and is probably |
… |
… |
class ClientHandler(BaseHandler):
|
112 | 115 | response.streaming_content = closing_iterator_wrapper( |
113 | 116 | response.streaming_content, response.close) |
114 | 117 | else: |
115 | | response.close() |
| 118 | request_finished.disconnect(close_connection) |
| 119 | response.close() # will fire request_finished |
| 120 | request_finished.connect(close_connection) |
116 | 121 | |
117 | 122 | return response |
118 | 123 | |
diff --git a/django/test/utils.py b/django/test/utils.py
index a1ff826..8114ae0 100644
a
|
b
|
from xml.dom.minidom import parseString, Node
|
4 | 4 | |
5 | 5 | from django.conf import settings, UserSettingsHolder |
6 | 6 | from django.core import mail |
7 | | from django.core.signals import request_finished |
8 | | from django.db import close_connection |
9 | 7 | from django.test.signals import template_rendered, setting_changed |
10 | 8 | from django.template import Template, loader, TemplateDoesNotExist |
11 | 9 | from django.template.loaders import cached |
… |
… |
def setup_test_environment():
|
70 | 68 | """Perform any global pre-test setup. This involves: |
71 | 69 | |
72 | 70 | - Installing the instrumented test renderer |
73 | | - Setting the email backend to the locmem email backend. |
| 71 | - Set the email backend to the locmem email backend. |
74 | 72 | - Setting the active locale to match the LANGUAGE_CODE setting. |
75 | | - Disconnecting the request_finished signal to avoid closing |
76 | | the database connection within tests. |
77 | 73 | """ |
78 | 74 | Template.original_render = Template._render |
79 | 75 | Template._render = instrumented_test_render |
… |
… |
def setup_test_environment():
|
85 | 81 | |
86 | 82 | deactivate() |
87 | 83 | |
88 | | request_finished.disconnect(close_connection) |
89 | | |
90 | 84 | |
91 | 85 | def teardown_test_environment(): |
92 | 86 | """Perform any global post-test teardown. This involves: |