Unittest's assertEqual and iterables - only check the contents

Python 3

  • If you don't care about the order of the content, you have the assertCountEqual(a,b) method
  • If you care about the order of the content, you have the assertSequenceEqual(a,b) method

Python >= 2.7

  • If you don't care about the order of the content, you have the assertItemsEqual(a,b) method
  • If you care about the order of the content, you have the assertSequenceEqual(a,b) method

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