summaryrefslogtreecommitdiff
path: root/tests/transactions
diff options
context:
space:
mode:
Diffstat (limited to 'tests/transactions')
-rw-r--r--tests/transactions/tests.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index 5c38bc8ef2..e7ce43cd93 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -202,8 +202,9 @@ class AtomicTests(TransactionTestCase):
# trigger a database error inside an inner atomic without savepoint
with self.assertRaises(DatabaseError):
with transaction.atomic(savepoint=False):
- connection.cursor().execute(
- "SELECT no_such_col FROM transactions_reporter")
+ with connection.cursor() as cursor:
+ cursor.execute(
+ "SELECT no_such_col FROM transactions_reporter")
# prevent atomic from rolling back since we're recovering manually
self.assertTrue(transaction.get_rollback())
transaction.set_rollback(False)
@@ -534,8 +535,8 @@ class TransactionRollbackTests(IgnoreDeprecationWarningsMixin, TransactionTestCa
available_apps = ['transactions']
def execute_bad_sql(self):
- cursor = connection.cursor()
- cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
+ with connection.cursor() as cursor:
+ cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
@skipUnlessDBFeature('requires_rollback_on_dirty_transaction')
def test_bad_sql(self):
@@ -678,6 +679,6 @@ class TransactionContextManagerTests(IgnoreDeprecationWarningsMixin, Transaction
"""
with self.assertRaises(IntegrityError):
with transaction.commit_on_success():
- cursor = connection.cursor()
- cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
+ with connection.cursor() as cursor:
+ cursor.execute("INSERT INTO transactions_reporter (first_name, last_name) VALUES ('Douglas', 'Adams');")
transaction.rollback()