Fixed #31233 -- Closed database connections and cursors after use.

This commit is contained in:
Jon Dufresne 2020-02-03 19:07:00 -08:00 committed by Mariusz Felisiak
parent f48f671223
commit 3259983f56
14 changed files with 86 additions and 55 deletions

View file

@ -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: