Opened 14 years ago
Closed 13 years ago
#14503 closed Cleanup/optimization (fixed)
Unify test for exception+message value assertion method
Reported by: | Ramiro Morales | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Currently we have a few copies of methods with similar tasks:
$ ack def\ assertRaises --python [...] tests/regressiontests/forms/fields.py 52: def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs): tests/regressiontests/forms/localflavor/be.py 11: def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs): tests/regressiontests/utils/datastructures.py 11: def assertRaisesErrorWithMessage(self, error, message, callable, tests/regressiontests/queries/tests.py 24: def assertRaisesMessage(self, exc, msg, func, *args, **kwargs): tests/regressiontests/fixtures_regress/tests.py 340: def assertRaisesMessage(self, exc, msg, func, *args, **kwargs): tests/regressiontests/urlpatterns_reverse/tests.py 136: def assertRaisesErrorWithMessage(self, error, message, callable, tests/regressiontests/custom_columns_regress/tests.py 12: def assertRaisesMessage(self, exc, msg, func, *args, **kwargs): tests/regressiontests/admin_validation/tests.py 21: def assertRaisesMessage(self, exc, msg, func, *args, **kwargs): tests/regressiontests/file_storage/tests.py 35: def assertRaisesErrorWithMessage(self, error, message, callable,
And some of them even run the callable twice:
def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs): self.assertRaises(error, callable, *args, **kwargs) try: callable(*args, **kwargs) except error, e: self.assertEqual(message, str(e))
Attachments (6)
Change History (9)
by , 14 years ago
Attachment: | 14503-assertraisesmessage-unification-simple.diff added |
---|
by , 14 years ago
Attachment: | 14503-replacement-with-assertraisesregexp.diff added |
---|
Different strategy as sugested by Alex: Migrate to use assertRaisesRegexp() unittest2.TestCase method
by , 14 years ago
Attachment: | 14503-replacement-with-assertraisesregexp.2.diff added |
---|
Same as previous one, moving inheritance of some non-DB tests from django.test.TestCase back to django.utils.unittest.TestCase
by , 14 years ago
Attachment: | 14503-assertraisesregex-r14981.diff added |
---|
Updated patch for trunk as of now
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 13 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
by , 13 years ago
Attachment: | 14503-with-testcase-class.diff added |
---|
Similar patch but using a thin subclass of django.utuls.unitest.TestCase
Note:
See TracTickets
for help on using tickets.
Simple unification using a new django.test.{Transaction,}TestCase() method