From ae32e337e0fd7547cce9bce04be1cf256e0a7bd5 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 9 Jul 2021 07:38:31 +0200 Subject: [PATCH] Fixed isolation of NonAutocommitTests.test_orm_query_after_error_and_rollback(). --- tests/transactions/tests.py | 15 ++++++++------- 1 file 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):