mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #31233 -- Closed database connections and cursors after use.
This commit is contained in:
parent
f48f671223
commit
3259983f56
14 changed files with 86 additions and 55 deletions
|
@ -114,8 +114,8 @@ class Tests(TestCase):
|
|||
|
||||
try:
|
||||
# Open a database connection.
|
||||
new_connection.cursor()
|
||||
self.assertFalse(new_connection.get_autocommit())
|
||||
with new_connection.cursor():
|
||||
self.assertFalse(new_connection.get_autocommit())
|
||||
finally:
|
||||
new_connection.close()
|
||||
|
||||
|
@ -149,9 +149,12 @@ class Tests(TestCase):
|
|||
|
||||
def test_connect_no_is_usable_checks(self):
|
||||
new_connection = connection.copy()
|
||||
with mock.patch.object(new_connection, 'is_usable') as is_usable:
|
||||
new_connection.connect()
|
||||
is_usable.assert_not_called()
|
||||
try:
|
||||
with mock.patch.object(new_connection, 'is_usable') as is_usable:
|
||||
new_connection.connect()
|
||||
is_usable.assert_not_called()
|
||||
finally:
|
||||
new_connection.close()
|
||||
|
||||
def _select(self, val):
|
||||
with connection.cursor() as cursor:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue