Unit testing beginner question
Ian Kelly
ian.g.kelly at gmail.com
Mon May 23 18:46:52 EDT 2011
On Mon, May 23, 2011 at 4:30 PM, Andrius <andrius.a at 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
More information about the Python-list
mailing list