Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6101
| References | <b34bbd5b-bd87-43e0-85a9-1cfbdcc4ca8c@y12g2000yqh.googlegroups.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2011-05-23 16:46 -0600 |
| Subject | Re: Unit testing beginner question |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1991.1306191316.9059.python-list@python.org> (permalink) |
On Mon, May 23, 2011 at 4:30 PM, Andrius <andrius.a@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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Unit testing beginner question Andrius <andrius.a@gmail.com> - 2011-05-23 15:30 -0700
Re: Unit testing beginner question Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-23 16:46 -0600
Re: Unit testing beginner question Roy Smith <roy@panix.com> - 2011-05-23 20:19 -0400
csiph-web