Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4027
| From | Duncan Booth <duncan.booth@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Case study: debugging failed assertRaises bug |
| Date | 2011-04-26 09:22 +0000 |
| Message-ID | <Xns9ED369ACDD677duncanbooth@127.0.0.1> (permalink) |
| References | <4db66095$0$29978$c3e8da3$5496439d@news.astraweb.com> |
Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> (1) assertRaises REALLY needs a better error message. If not a custom
> message, at least it should show the result it got instead of an
> exception.
>
If a different exception was thrown then you get an error instead of a
failure and you are shown the Exception that was thrown, so I think you
only have an issue if no exception was thrown at all.
If so, here's an alternative way to write your test which might be easier
to debug:
def testBadArgType(self):
# Test failures with bad argument types.
for d in (None, 23, object(), "spam"):
with self.assertRaises(TypeError) as cm:
self.func(d)
print(d, "didn't throw the exception")
It is worth remembering that print output doesn't appear unless the test
fails, so you can leave the tracing statement in the test. Also,
assertRaises has a weird dual life as a context manager: I never knew that
before today.
--
Duncan Booth http://kupuguy.blogspot.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Case study: debugging failed assertRaises bug Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-26 06:05 +0000
Re: Case study: debugging failed assertRaises bug Duncan Booth <duncan.booth@invalid.invalid> - 2011-04-26 09:22 +0000
Re: Case study: debugging failed assertRaises bug Raymond Hettinger <python@rcn.com> - 2011-04-26 14:10 -0700
Re: Case study: debugging failed assertRaises bug Ben Finney <ben+python@benfinney.id.au> - 2011-04-27 10:14 +1000
Re: Case study: debugging failed assertRaises bug R David Murray <rdmurray@bitdance.com> - 2011-04-27 14:54 +0000
csiph-web