Unittest's assertEqual and iterables - only check the contents Unittest's assertEqual and iterables - only check the contents python python

Unittest's assertEqual and iterables - only check the contents


Python 3

Python >= 2.7


You can always add your own assertion methods to your TestCase class:

def assertSequenceEqual(self, it1, it2):    self.assertEqual(tuple(it1), tuple(it2))

or take a look at how 2.7 defined it: http://hg.python.org/cpython/file/14cafb8d1480/Lib/unittest/case.py#l621


It looks to me you care about the order of items in the sequences. Therefore, assertItemsEqual/assertCountEqual is not for you.

In Python 2.7 and in Python 3, what you want is self.assertSequenceEqual. This is sensitive to the order of the items.