diff options
Diffstat (limited to 'tests/transaction_hooks')
| -rw-r--r-- | tests/transaction_hooks/tests.py | 34 |
1 files changed, 10 insertions, 24 deletions
diff --git a/tests/transaction_hooks/tests.py b/tests/transaction_hooks/tests.py index 000de4104c..049211139d 100644 --- a/tests/transaction_hooks/tests.py +++ b/tests/transaction_hooks/tests.py @@ -1,3 +1,5 @@ +from contextlib import suppress + from django.db import connection, transaction from django.test import TransactionTestCase, skipUnlessDBFeature @@ -48,12 +50,10 @@ class TestConnectionOnCommit(TransactionTestCase): self.assertDone([1]) def test_does_not_execute_if_transaction_rolled_back(self): - try: + with suppress(ForcedError): with transaction.atomic(): self.do(1) raise ForcedError() - except ForcedError: - pass self.assertDone([]) @@ -71,12 +71,10 @@ class TestConnectionOnCommit(TransactionTestCase): with transaction.atomic(): self.do(1) # one failed savepoint - try: + with suppress(ForcedError): with transaction.atomic(): self.do(2) raise ForcedError() - except ForcedError: - pass # another successful savepoint with transaction.atomic(): self.do(3) @@ -86,25 +84,21 @@ class TestConnectionOnCommit(TransactionTestCase): def test_no_hooks_run_from_failed_transaction(self): """If outer transaction fails, no hooks from within it run.""" - try: + with suppress(ForcedError): with transaction.atomic(): with transaction.atomic(): self.do(1) raise ForcedError() - except ForcedError: - pass self.assertDone([]) def test_inner_savepoint_rolled_back_with_outer(self): with transaction.atomic(): - try: + with suppress(ForcedError): with transaction.atomic(): with transaction.atomic(): self.do(1) raise ForcedError() - except ForcedError: - pass self.do(2) self.assertDone([2]) @@ -113,11 +107,9 @@ class TestConnectionOnCommit(TransactionTestCase): with transaction.atomic(): with transaction.atomic(): self.do(1) - try: + with suppress(ForcedError): with transaction.atomic(savepoint=False): raise ForcedError() - except ForcedError: - pass self.assertDone([]) @@ -125,11 +117,9 @@ class TestConnectionOnCommit(TransactionTestCase): with transaction.atomic(): with transaction.atomic(): self.do(1) - try: + with suppress(ForcedError): with transaction.atomic(): raise ForcedError() - except ForcedError: - pass self.assertDone([1]) @@ -151,12 +141,10 @@ class TestConnectionOnCommit(TransactionTestCase): self.assertDone([1, 2]) # not [1, 1, 2] def test_hooks_cleared_after_rollback(self): - try: + with suppress(ForcedError): with transaction.atomic(): self.do(1) raise ForcedError() - except ForcedError: - pass with transaction.atomic(): self.do(2) @@ -177,11 +165,9 @@ class TestConnectionOnCommit(TransactionTestCase): self.assertDone([2]) def test_error_in_hook_doesnt_prevent_clearing_hooks(self): - try: + with suppress(ForcedError): with transaction.atomic(): transaction.on_commit(lambda: self.notify('error')) - except ForcedError: - pass with transaction.atomic(): self.do(1) |
