From 7a6fbf36b1fdb8978ea0842075ccce83bcd63789 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Tue, 28 Nov 2017 05:12:28 -0800 Subject: Fixed #28853 -- Updated connection.cursor() uses to use a context manager. --- tests/db_utils/tests.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/db_utils') diff --git a/tests/db_utils/tests.py b/tests/db_utils/tests.py index 2a45342df5..4e35e6bb8b 100644 --- a/tests/db_utils/tests.py +++ b/tests/db_utils/tests.py @@ -26,10 +26,10 @@ class DatabaseErrorWrapperTests(TestCase): @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL test') def test_reraising_backend_specific_database_exception(self): - cursor = connection.cursor() - msg = 'table "X" does not exist' - with self.assertRaisesMessage(ProgrammingError, msg) as cm: - cursor.execute('DROP TABLE "X"') + with connection.cursor() as cursor: + msg = 'table "X" does not exist' + with self.assertRaisesMessage(ProgrammingError, msg) as cm: + cursor.execute('DROP TABLE "X"') self.assertNotEqual(type(cm.exception), type(cm.exception.__cause__)) self.assertIsNotNone(cm.exception.__cause__) self.assertIsNotNone(cm.exception.__cause__.pgcode) -- cgit v1.3