<p>给定</p>
<pre class="lang-py prettyprint-override"><code>l1 = [a,b]
l2 = [b,a]
</code></pre>
<p><a href="http://docs.python.org/3/library/unittest.html?highlight=assertcountequal#unittest.TestCase.assertCountEqual" rel="nofollow noreferrer">In Python <em>>= 3.0</em></a></p>
<pre class="lang-py prettyprint-override"><code>assertCountEqual(l1, l2) # True
</code></pre>
<p><a href="http://docs.python.org/library/unittest.html?highlight=assertequal#unittest.TestCase.assertItemsEqual" rel="nofollow noreferrer">In Python <em>>= 2.7</em></a>,上面的函数名为:</p>
<pre class="lang-py prettyprint-override"><code>assertItemsEqual(l1, l2) # True
</code></pre>
<p><a href="https://pypi.python.org/pypi/unittest2" rel="nofollow noreferrer">In Python <em>< 2.7</em></a></p>
<pre class="lang-py prettyprint-override"><code>import unittest2
assertItemsEqual(l1, l2) # True
</code></pre>
<p><a href="https://six.readthedocs.io/#six.assertCountEqual" rel="nofollow noreferrer">Via ^{<cd1>} module</a>(任何Python版本)</p>
<pre class="lang-py prettyprint-override"><code>import unittest
import six
class MyTest(unittest.TestCase):
def test(self):
six.assertCountEqual(self, self.l1, self.l2) # True
</code></pre>