diff options
author | Tim Graham <timograham@gmail.com> | 2017-09-07 08:16:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-07 08:16:21 -0400 |
commit | 6e4c6281dbb7ee12bcdc22620894edb4e9cf623f (patch) | |
tree | 1c21218d4b6f00c499f18943d5190ebe7b5248c9 /tests/transaction_hooks | |
parent | 8b2515a450ef376b9205029090af0a79c8341bd7 (diff) | |
download | django-6e4c6281dbb7ee12bcdc22620894edb4e9cf623f.tar.gz |
Reverted "Fixed #27818 -- Replaced try/except/pass with contextlib.suppress()."
This reverts commit 550cb3a365dee4edfdd1563224d5304de2a57fda
because try/except performs better.
Diffstat (limited to 'tests/transaction_hooks')
-rw-r--r-- | tests/transaction_hooks/tests.py | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/tests/transaction_hooks/tests.py b/tests/transaction_hooks/tests.py index ed3cf18be2..81ff0066a1 100644 --- a/tests/transaction_hooks/tests.py +++ b/tests/transaction_hooks/tests.py @@ -1,5 +1,3 @@ -from contextlib import suppress - from django.db import connection, transaction from django.test import TransactionTestCase, skipUnlessDBFeature @@ -50,10 +48,12 @@ class TestConnectionOnCommit(TransactionTestCase): self.assertDone([1]) def test_does_not_execute_if_transaction_rolled_back(self): - with suppress(ForcedError): + try: with transaction.atomic(): self.do(1) raise ForcedError() + except ForcedError: + pass self.assertDone([]) @@ -71,10 +71,12 @@ class TestConnectionOnCommit(TransactionTestCase): with transaction.atomic(): self.do(1) # one failed savepoint - with suppress(ForcedError): + try: with transaction.atomic(): self.do(2) raise ForcedError() + except ForcedError: + pass # another successful savepoint with transaction.atomic(): self.do(3) @@ -84,21 +86,25 @@ class TestConnectionOnCommit(TransactionTestCase): def test_no_hooks_run_from_failed_transaction(self): """If outer transaction fails, no hooks from within it run.""" - with suppress(ForcedError): + try: 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(): - with suppress(ForcedError): + try: with transaction.atomic(): with transaction.atomic(): self.do(1) raise ForcedError() + except ForcedError: + pass self.do(2) self.assertDone([2]) @@ -107,9 +113,11 @@ class TestConnectionOnCommit(TransactionTestCase): with transaction.atomic(): with transaction.atomic(): self.do(1) - with suppress(ForcedError): + try: with transaction.atomic(savepoint=False): raise ForcedError() + except ForcedError: + pass self.assertDone([]) @@ -117,9 +125,11 @@ class TestConnectionOnCommit(TransactionTestCase): with transaction.atomic(): with transaction.atomic(): self.do(1) - with suppress(ForcedError): + try: with transaction.atomic(): raise ForcedError() + except ForcedError: + pass self.assertDone([1]) @@ -141,10 +151,12 @@ class TestConnectionOnCommit(TransactionTestCase): self.assertDone([1, 2]) # not [1, 1, 2] def test_hooks_cleared_after_rollback(self): - with suppress(ForcedError): + try: with transaction.atomic(): self.do(1) raise ForcedError() + except ForcedError: + pass with transaction.atomic(): self.do(2) @@ -165,9 +177,11 @@ class TestConnectionOnCommit(TransactionTestCase): self.assertDone([2]) def test_error_in_hook_doesnt_prevent_clearing_hooks(self): - with suppress(ForcedError): + try: with transaction.atomic(): transaction.on_commit(lambda: self.notify('error')) + except ForcedError: + pass with transaction.atomic(): self.do(1) |