Unit testing beginner question

Andrius A andrius.a at gmail.com
Mon May 23 18:49:48 EDT 2011


That was quick! Thanks Ian


On 23 May 2011 23:46, Ian Kelly <ian.g.kelly at gmail.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110523/23c9a32d/attachment-0001.html>


More information about the Python-list mailing list