'Asserts that the message in a raised exception matches a regexp.
Args:
expected_exception: Exception class expected to be raised.
expected_regexp: Regexp (re pattern object or string) expected
to be found in error message.
callable_obj: Function to be called.
args: Extra args.
kwargs: Extra kwargs.'

def assertRaisesRegexp(self, expected_exception, expected_regexp, callable_obj=None, *args, **kwargs):

    if (callable_obj is None):
        return _AssertRaisesContext(expected_exception, self, expected_regexp)
    try:
        callable_obj(*args, **kwargs)
    except expected_exception as exc_value:
        if isinstance(expected_regexp, basestring):
            expected_regexp = re.compile(expected_regexp)
        if (not expected_regexp.search(str(exc_value))):
            raise self.failureException(('"%s"    does    not    match    "%s"' % (expected_regexp.pattern, str(exc_value))))
    else:
        if hasattr(expected_exception, '__name__'):
            excName = expected_exception.__name__
        else:
            excName = str(expected_exception)
        raise self.failureException(('%s    not    raised' % excName))
