Skip to content

Instantly share code, notes, and snippets.

@felipe-prenholato
Created October 10, 2011 14:53
Show Gist options
  • Save felipe-prenholato/1275520 to your computer and use it in GitHub Desktop.
Save felipe-prenholato/1275520 to your computer and use it in GitHub Desktop.
class ExTestCase(TestCase):
def assertRaisesMessage(self, expected_exception, expected_message,
callable_obj=None, *args, **kwargs):
"""
Asserts that the message in a raised exception matches the passed
value.
Args:
expected_exception: Exception class expected to be raised.
expected_message: expected error message string value.
callable_obj: Function to be called.
args: Extra args.
kwargs: Extra kwargs.
"""
try:
callable_obj(*args,**kwargs)
except Exception, err:
self.assertTrue(isinstance(err,expected_exception),u"Raise something unexpected!")
self.assertEquals(err.message,expected_message)
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment