On Mon, May 23, 2011 at 4:30 PM, Andrius <andriu...@gmail.com> wrote: > and I am expecting test to pass, but I am getting exception: > Traceback (most recent call last): > self.assertRaises(TypeError, self.testListNone[:1]) > TypeError: 'NoneType' object is unsubscriptable > > I thought that assertRaises will pass since TypeError exception will > be raised?
The second argument to assertRaises must be a function that assertRaises will call. assertRaises can't catch the error above because it is raised when the argument is evaluated, before assertRaises has even been called. This would work: self.assertRaises(TypeError, lambda: self.testListNone[:1]) Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list