summaryrefslogtreecommitdiff
path: root/tests/transactions
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-07-09 07:38:31 +0200
committerGitHub <noreply@github.com>2021-07-09 07:38:31 +0200
commitae32e337e0fd7547cce9bce04be1cf256e0a7bd5 (patch)
treebb6cc7fae9edb14690ae90e6783d705f90e572ec /tests/transactions
parent7bb0605a8c4adb4247a179276036f138ae859ac9 (diff)
downloaddjango-ae32e337e0fd7547cce9bce04be1cf256e0a7bd5.tar.gz
Fixed isolation of NonAutocommitTests.test_orm_query_after_error_and_rollback().
Diffstat (limited to 'tests/transactions')
-rw-r--r--tests/transactions/tests.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index dc163be6c5..ccad5ca76c 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -477,12 +477,18 @@ class NonAutocommitTests(TransactionTestCase):
available_apps = []
+ def setUp(self):
+ transaction.set_autocommit(False)
+
+ def tearDown(self):
+ transaction.rollback()
+ transaction.set_autocommit(True)
+
def test_orm_query_after_error_and_rollback(self):
"""
ORM queries are allowed after an error and a rollback in non-autocommit
mode (#27504).
"""
- transaction.set_autocommit(False)
r1 = Reporter.objects.create(first_name='Archibald', last_name='Haddock')
r2 = Reporter(first_name='Cuthbert', last_name='Calculus', id=r1.id)
with self.assertRaises(IntegrityError):
@@ -492,12 +498,7 @@ class NonAutocommitTests(TransactionTestCase):
def test_orm_query_without_autocommit(self):
"""#24921 -- ORM queries must be possible after set_autocommit(False)."""
- transaction.set_autocommit(False)
- try:
- Reporter.objects.create(first_name="Tintin")
- finally:
- transaction.rollback()
- transaction.set_autocommit(True)
+ Reporter.objects.create(first_name="Tintin")
class DurableTests(TransactionTestCase):