This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ezio.melotti
Recipients ezio.melotti, michael.foord, pitrou, r.david.murray, serhiy.storchaka, simonzack
Date 2014-09-21.18:29:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1411324163.84.0.716992603099.issue22452@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-09-21 18:29:23ezio.melottisetrecipients: + ezio.melotti, pitrou, r.david.murray, michael.foord, serhiy.storchaka, simonzack
2014-09-21 18:29:23ezio.melottisetmessageid: <1411324163.84.0.716992603099.issue22452@psf.upfronthosting.co.za>
2014-09-21 18:29:23ezio.melottilinkissue22452 messages
2014-09-21 18:29:23ezio.melotticreate