From 109b33f64c8d3f48c9e0bd3ea8d42fe6f3cb02b7 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 19 Jan 2017 21:10:33 -0500 Subject: Refs #23919 -- Simplified assertRaisesRegex()'s that accounted for Python 2. --- tests/test_utils/tests.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tests/test_utils') diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index f8eda7ed39..b1c35d1f80 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -362,22 +362,26 @@ class AssertTemplateUsedContextManagerTests(SimpleTestCase): pass def test_error_message(self): - with self.assertRaisesRegex(AssertionError, r'^template_used/base\.html'): + msg = 'template_used/base.html was not rendered. No template was rendered.' + with self.assertRaisesMessage(AssertionError, msg): with self.assertTemplateUsed('template_used/base.html'): pass - with self.assertRaisesRegex(AssertionError, r'^template_used/base\.html'): + with self.assertRaisesMessage(AssertionError, msg): with self.assertTemplateUsed(template_name='template_used/base.html'): pass - with self.assertRaisesRegex(AssertionError, r'^template_used/base\.html.*template_used/alternative\.html$'): + msg2 = ( + 'template_used/base.html was not rendered. Following templates ' + 'were rendered: template_used/alternative.html' + ) + with self.assertRaisesMessage(AssertionError, msg2): with self.assertTemplateUsed('template_used/base.html'): render_to_string('template_used/alternative.html') - with self.assertRaises(AssertionError) as cm: + with self.assertRaisesMessage(AssertionError, 'No templates used to render the response'): response = self.client.get('/test_utils/no_template_used/') self.assertTemplateUsed(response, 'template_used/base.html') - self.assertEqual(cm.exception.args[0], "No templates used to render the response") def test_failure(self): with self.assertRaises(TypeError): -- cgit v1.3