[py-dev] Advanced assert equal

Floris Bruynooghe flub at devork.be
Mon Aug 16 02:25:57 CEST 2010


Hi

Ever since unittest grew it's .assertSequenceEqual() and
.assertMultilineEqual() I've been jealous of it.  So this weekend I've
looked into the py.test code and made an attempt at getting this into
my favourite testing tool.

The attached patch makes compare equal a special case and checks if
the two arguments to it are both a list, text or dict and tries to
generate a nicer explanation text for them.  The patch is more like a
proof of concept then a final implementation, I may have done some
very strange or silly things as I'm not familiar with the code.  It
would be great to get feedback, both on the general concept and the
actual implementation (particularly note the way I had to hack
_format_explanation() in assertion.py).

Some of the rough edges I can think off right now: (i) no idea how
comparisons and nested calls work together, (ii) no attempt is made to
limit the output from difflib so the screen doesn't get flooded.
There's probably many more.

I hope this can be useful
Floris

-- 
Debian GNU/Linux -- The Power of Freedom
www.debian.org | www.gnu.org | www.kernel.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: py.test.diff
Type: text/x-diff
Size: 6744 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20100816/672c190c/attachment.diff>


More information about the Pytest-dev mailing list