[Python-ideas] Comparable exceptions
Ryan Gonzalez
rymg19 at gmail.com
Wed Feb 25 00:57:32 CET 2015
Doesn't unittest already cover this?
with self.assertRaisesRegexp(OSError, '^foobar$'):
do_something()
On Tue, Feb 24, 2015 at 5:43 PM, Ionel Cristian Mărieș <contact at ionelmc.ro>
wrote:
> Hey everyone,
>
> I was writing a test the other day and I wanted to assert that some
> function raises some exception, but with some exact value. Turns out you
> cannot compare OSError("foobar") to OSError("foobar") as it doesn't have
> any __eq__. (it's the same for all exceptions?)
>
> I think exceptions are great candidates to have an __eq__ method - they
> already have a __hash__ (that's computed from the contained values) and
> they are already containers in a way (they all have the `args` attribute).
>
> Comparing exceptions in a test assertion seems like a good usecase for
> this.
>
> Thanks,
> -- Ionel Cristian Mărieș, blog.ionelmc.ro
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple:
"It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
nul-terminated."
Personal reality distortion fields are immune to contradictory evidence. -
srean
Check out my website: http://kirbyfan64.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150224/f674c8af/attachment.html>
More information about the Python-ideas
mailing list