Ticket #17640: 17640-2.diff

File 17640-2.diff, 1.5 KB (added by Claude Paroz, 13 years ago)

Use assertRaisesRegexp

  • tests/regressiontests/test_utils/tests.py

    diff --git a/tests/regressiontests/test_utils/tests.py b/tests/regressiontests/test_utils/tests.py
    index 72a8154..c68f07e 100644
    a b class AssertTemplateUsedContextManagerTests(TestCase):  
    136136            pass
    137137
    138138    def test_error_message(self):
    139         try:
     139        with self.assertRaisesRegexp(AssertionError, '^template_used/base\.html'):
    140140            with self.assertTemplateUsed('template_used/base.html'):
    141141                pass
    142         except AssertionError, e:
    143             self.assertTrue('template_used/base.html' in e.message)
    144142
    145         try:
     143        with self.assertRaisesRegexp(AssertionError, '^template_used/base\.html'):
    146144            with self.assertTemplateUsed(template_name='template_used/base.html'):
    147145                pass
    148         except AssertionError, e:
    149             self.assertTrue('template_used/base.html' in e.message)
    150146
    151         try:
     147        with self.assertRaisesRegexp(AssertionError,
     148            '^template_used/base\.html.*template_used/alternative\.html$'):
    152149            with self.assertTemplateUsed('template_used/base.html'):
    153150                render_to_string('template_used/alternative.html')
    154         except AssertionError, e:
    155             self.assertTrue('template_used/base.html' in e.message, e.message)
    156             self.assertTrue('template_used/alternative.html' in e.message, e.message)
    157151
    158152    def test_failure(self):
    159153        with self.assertRaises(TypeError):
Back to Top