summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@rd.io>2012-09-07 15:06:23 -0400
committerAlex Gaynor <alex.gaynor@rd.io>2012-09-07 15:08:07 -0400
commit335a9f9cf1e2f40679e91cf42cfd0e636885a397 (patch)
tree1fa3e8a43e1bd0d884e5f810f229a3c35ed4381d /tests
parent257c4011cb887524048acb8796b130761617d195 (diff)
Removed many uses of bare "except:", which were either going to a) silence real issues, or b) were impossible to hit.
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/file_uploads/tests.py2
-rw-r--r--tests/regressiontests/handlers/tests.py4
-rw-r--r--tests/regressiontests/queries/tests.py5
-rw-r--r--tests/regressiontests/transactions_regress/tests.py22
4 files changed, 10 insertions, 23 deletions
diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
index a545ed649e..f28d658f52 100644
--- a/tests/regressiontests/file_uploads/tests.py
+++ b/tests/regressiontests/file_uploads/tests.py
@@ -100,7 +100,7 @@ class FileUploadTests(TestCase):
try:
os.unlink(file1.name)
- except:
+ except OSError:
pass
self.assertEqual(response.status_code, 200)
diff --git a/tests/regressiontests/handlers/tests.py b/tests/regressiontests/handlers/tests.py
index ae2062c756..34863b6493 100644
--- a/tests/regressiontests/handlers/tests.py
+++ b/tests/regressiontests/handlers/tests.py
@@ -17,10 +17,8 @@ class HandlerTests(unittest.TestCase):
# Try running the handler, it will fail in load_middleware
handler = WSGIHandler()
self.assertEqual(handler.initLock.locked(), False)
- try:
+ with self.assertRaises(Exception):
handler(None, None)
- except:
- pass
self.assertEqual(handler.initLock.locked(), False)
# Reset settings
settings.MIDDLEWARE_CLASSES = old_middleware_classes
diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
index 005aa9650b..71ac107486 100644
--- a/tests/regressiontests/queries/tests.py
+++ b/tests/regressiontests/queries/tests.py
@@ -1677,10 +1677,7 @@ class CloneTests(TestCase):
list(n_list)
# Use the note queryset in a query, and evalute
# that query in a way that involves cloning.
- try:
- self.assertEqual(ExtraInfo.objects.filter(note__in=n_list)[0].info, 'good')
- except:
- self.fail('Query should be clonable')
+ self.assertEqual(ExtraInfo.objects.filter(note__in=n_list)[0].info, 'good')
class EmptyQuerySetTests(TestCase):
diff --git a/tests/regressiontests/transactions_regress/tests.py b/tests/regressiontests/transactions_regress/tests.py
index 90b3df03d4..472e2aafd9 100644
--- a/tests/regressiontests/transactions_regress/tests.py
+++ b/tests/regressiontests/transactions_regress/tests.py
@@ -1,7 +1,6 @@
from __future__ import absolute_import
-from django.core.exceptions import ImproperlyConfigured
-from django.db import connection, connections, transaction, DEFAULT_DB_ALIAS
+from django.db import connection, connections, transaction, DEFAULT_DB_ALIAS, DatabaseError
from django.db.transaction import commit_on_success, commit_manually, TransactionManagementError
from django.test import TransactionTestCase, skipUnlessDBFeature
from django.test.utils import override_settings
@@ -151,21 +150,14 @@ class TestTransactionClosing(TransactionTestCase):
# Create a user
create_system_user()
- try:
- # The second call to create_system_user should fail for violating a unique constraint
- # (it's trying to re-create the same user)
+ with self.assertRaises(DatabaseError):
+ # The second call to create_system_user should fail for violating
+ # a unique constraint (it's trying to re-create the same user)
create_system_user()
- except:
- pass
- else:
- raise ImproperlyConfigured('Unique constraint not enforced on django.contrib.auth.models.User')
- try:
- # Try to read the database. If the last transaction was indeed closed,
- # this should cause no problems
- _ = User.objects.all()[0]
- except:
- self.fail("A transaction consisting of a failed operation was not closed.")
+ # Try to read the database. If the last transaction was indeed closed,
+ # this should cause no problems
+ User.objects.all()[0]
@override_settings(DEBUG=True)
def test_failing_query_transaction_closed_debug(self):