Opened 5 years ago

Closed 4 years ago

#14503 closed Cleanup/optimization (fixed)

Unify test for exception+message value assertion method

Reported by: ramiro Owned by: nobody
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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)

14503-assertraisesmessage-unification-simple.diff (73.4 KB) - added by ramiro 5 years ago.
Simple unification using a new django.test.{Transaction,}TestCase() method
14503-replacement-with-assertraisesregexp.diff (82.7 KB) - added by ramiro 5 years ago.
Different strategy as sugested by Alex: Migrate to use assertRaisesRegexp() unittest2.TestCase method
14503-replacement-with-assertraisesregexp.2.diff (82.4 KB) - added by ramiro 5 years ago.
Same as previous one, moving inheritance of some non-DB tests from django.test.TestCase back to django.utils.unittest.TestCase
14503-assertraisesregex-r14981.diff (79.7 KB) - added by ramiro 5 years ago.
Updated patch for trunk as of now
14503-with-mixin.diff (70.1 KB) - added by ramiro 4 years ago.
Uupdated patch
14503-with-testcase-class.diff (70.4 KB) - added by ramiro 4 years ago.
Similar patch but using a thin subclass of django.utuls.unitest.TestCase

Download all attachments as: .zip

Change History (9)

Changed 5 years ago by ramiro

Simple unification using a new django.test.{Transaction,}TestCase() method

Changed 5 years ago by ramiro

Different strategy as sugested by Alex: Migrate to use assertRaisesRegexp() unittest2.TestCase method

Changed 5 years ago by ramiro

Same as previous one, moving inheritance of some non-DB tests from django.test.TestCase back to django.utils.unittest.TestCase

Changed 5 years ago by ramiro

Updated patch for trunk as of now

comment:1 Changed 5 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Cleanup/optimization

Changed 4 years ago by ramiro

Uupdated patch

Changed 4 years ago by ramiro

Similar patch but using a thin subclass of django.utuls.unitest.TestCase

comment:3 Changed 4 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to closed

In [16610]:

Fixed #14503 -- Unified multiple implementations of test cases assert* methods that verify a given exception is raised by a callable throughout the Django test suite.

Replaced them with a new assertRaisesMessage method of a new SimpleTestCase, a lightweight subclass of unittest.TestCase. Both are also available for usage in user tests.

Note: See TracTickets for help on using tickets.
Back to Top