title: Recursive AssertCountEqual in unittest
body: <p>I am writing a simple test for a function that should take as input an iterable and produce a list of all possible <a href="https://en.wikipedia.org/wiki/Partition_of_a_set" rel="nofollow noreferrer">partitions</a> of the input:</p>
  <pre class="lang-py prettyprint-override"><code>def partitions(collection):
    &quot;&quot;&quot; Iterator over partitions of collection
        https://stackoverflow.com/a/30134039/4841832
    &quot;&quot;&quot;
    if len(collection) == 1:
      yield [ collection ]
      return
  
    first = collection[0]
    for smaller in partitions(collection[1:]):
      # insert `first` in each of the subpartition's subsets
      for n, subset in enumerate(smaller):
        yield smaller[:n] + [[ first ] + subset]  + smaller[n+1:]
      # put `first` in its own subset 
      yield [ [ first ] ] + smaller
  </code></pre>
  <p>I tried using assertCountEquals for my test, but this does not work - it only checks for surface level similarity of the containers, instead of the 2 level similarity I need for my function.</p>
  <pre class="lang-py prettyprint-override"><code>def test_partitions(self):
        s = list(partitions([1,2,3]))
        self.assertCountEqual(s, [
          [[1,2,3]],
          [[1], [2,3]],
          [[2], [1,3]],
          [[3], [1,2]],
          [[1], [2], [3]]
        ])
  </code></pre>
  <pre><code>======================================================================
  FAIL: test_partitions (explainbn.test.test_utilities.TestIterationUtilities)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File &quot;...\test\test_utilities.py&quot;, line 124, in test_partitions
      self.assertCountEqual(s, [
  AssertionError: Element counts were not equal:
  First has 1, Second has 0:  [[1, 2], [3]]
  First has 0, Second has 1:  [[3], [1, 2]]
  
  ----------------------------------------------------------------------
  </code></pre>
  <p>What is the best way to write the test to achieve what I want? I don't care about the order of the elements or the type of the containers.</p>