Ticket #25188: 25188.diff

File 25188.diff, 1.3 KB (added by Tim Graham, 9 years ago)
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    index 2ea5190..2b0590f 100644
    a b import threading  
    1212import unittest
    1313import warnings
    1414from collections import Counter
     15from contextlib import contextmanager
    1516from copy import copy
    1617from functools import wraps
    1718from unittest.util import safe_repr
    class SimpleTestCase(unittest.TestCase):  
    604605            msg_prefix + "Template '%s' was used unexpectedly in rendering"
    605606            " the response" % template_name)
    606607
     608    @contextmanager
    607609    def assertRaisesMessage(self, expected_exception, expected_message, *args, **kwargs):
    608610        """
    609611        Asserts that the message in a raised exception matches the passed
    class SimpleTestCase(unittest.TestCase):  
    623625                'as an arg instead.', RemovedInDjango20Warning
    624626            )
    625627            args = (callable_obj,) + args
    626         return six.assertRaisesRegex(self, expected_exception,
    627                 re.escape(expected_message), *args, **kwargs)
     628
     629        with self.assertRaises(expected_exception) as cm:
     630            yield cm
     631        err = cm.exception
     632        self.assertIn(expected_message, str(err))
    628633
    629634    def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None,
    630635            field_kwargs=None, empty_value=''):
Back to Top