[Python-ideas] Comparable exceptions (original) (raw)
Ionel Cristian Mărieș contact at ionelmc.ro
Wed Feb 25 14:03:40 CET 2015
- Previous message: [Python-ideas] Comparable exceptions
- Next message: [Python-ideas] Comparable exceptions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Yes, it does, however my assertion looks similar to this:
assert result == [1,2, (3, 4, {"bubu": OSError('foobar')})]
I could implement my own "reliable_compare" function but I'd rather not do that, as it seems like a workaround.
Thanks, -- Ionel Cristian Mărieș, blog.ionelmc.ro
On Wed, Feb 25, 2015 at 1:57 AM, Ryan Gonzalez <rymg19 at gmail.com> wrote:
Doesn't unittest already cover this?
with self.assertRaisesRegexp(OSError, '^foobar$'): dosomething()
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/20150225/910c00d2/attachment-0001.html>
- Previous message: [Python-ideas] Comparable exceptions
- Next message: [Python-ideas] Comparable exceptions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]