Reputation: 31
May I know why this test fails even though the function actually throws the exception?
def testDateCreation(self):
self.assertRaises(ValueError, datetime.date(2013, 2, 29))
Upvotes: 2
Views: 494
Reputation: 101052
You either have to use assertRaises
as context manager (if running python 2.7):
with self.assertRaises(ValueError):
datetime.date(2013, 2, 29)
or provide a function which assertRaises
can call:
self.assertRaises(ValueError, lambda: datetime.date(2013, 2, 29))
Otherwise, the exception is raised before assertRaises
is called, and thus can't be handled.
Upvotes: 2