[issue27060] Documentation of assertItemsEqual in unittest is VERY misleading in 2.7

Vitaly report at bugs.python.org
Fri May 20 19:37:59 EDT 2016


Vitaly added the comment:

Thanks Terry, your assessment is correct. The maintainers appear to have drawn the wrong conclusion in #17866, which mislead me about the existing assertItemsEqual in 2.7, which appears to work correctly after all!

import unittest as u
class Test(u.TestCase):
    def test_equal_count_of_same_elements(self):
        self.assertItemsEqual([1,2,3], [1,2,3])

    def test_equal_count_of_different_elements(self):
        self.assertItemsEqual([1,2,3], [1,2,4])

    def test_different_count(self):
        self.assertItemsEqual([1,2,3], [1,2,3,4])
u.main()


$ python assert_items_equal_test.py --verbose
test_different_count (__main__.Test) ... FAIL
test_equal_count_of_different_elements (__main__.Test) ... FAIL
test_equal_count_of_same_elements (__main__.Test) ... ok

======================================================================
FAIL: test_different_count (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "assert_items_equal_test.py", line 12, in test_different_count
    self.assertItemsEqual([1,2,3], [1,2,3,4])
AssertionError: Element counts were not equal:
First has 0, Second has 1:  4

======================================================================
FAIL: test_equal_count_of_different_elements (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "assert_items_equal_test.py", line 8, in test_equal_count_of_different_elements
    self.assertItemsEqual([1,2,3], [1,2,4])
AssertionError: Element counts were not equal:
First has 1, Second has 0:  3
First has 0, Second has 1:  4

----------------------------------------------------------------------
Ran 3 tests in 0.001s

FAILED (failures=2)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27060>
_______________________________________


More information about the Python-bugs-list mailing list