Ezio Melotti added the comment:
Currently assertListEqual calls assertSequenceEqual, and assertSequenceEqual
doesn't use any function to compare list elements -- it just does "if item1 !=
item2:" (https://hg.python.org/cpython/file/default/Lib/unittest/case.py).
Checking the types of the two items and compare them recursively could be done,
but it's not as simple as it sounds, since using e.g. assertSequenceEqual will
raise an error message that will need to be caught and integrated with the
error message that it's already being constructed, possibly resulting in a long
and unreadable message.
Since this is a somewhat specific situation, it might be better if you just
defined your own assert function for nested lists. In addition to nested lists
you might have a dictionary that contains lists, or a set of tuples or any
other combinations of arbitrarily nested containers, and having a generic way
to handle them all will require quite a lot of work.
One thing that could be done is to add more attributes to the exception raised
by assertSequenceEqual (and others), so that you could do something like:
try:
self.assertEqual(nested_list1, nested_list2)
except AssertionError as exc:
index = exc.first_differing_index
self.assertEqual(nested_list1[index], nested_list2[index], msg=str(exc))
Not sure how that will look light though, and it's still not a generic
solution, but if you know what are you dealing with, it might be helpful.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue22452>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com