This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: TestCase.assertItemsEqual exists in 2.7, not in 3.3
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: docs@python, ezio.melotti, flox, python-dev, r.david.murray, ronaldoussoren, vitaly
Priority: normal Keywords: patch

Created on 2013-04-29 08:01 by ronaldoussoren, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
issue17866.txt ronaldoussoren, 2013-04-29 08:59
issue17866.diff ezio.melotti, 2013-04-29 09:08
issue17866-2.diff ezio.melotti, 2013-04-29 09:19
Messages (14)
msg188045 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-04-29 08:01
assertItemsEqual was added to unittest.TestCase in Python 2.7 (according to the documentation), but is not present in Python 3.3.

I'd expect it to be present in 3.3 as well, or for it to be mentioned in documentation as not being present (either in the 2.7 documentation or the Misc/NEWS file for py3k)
msg188046 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-04-29 08:15
I don't remember how it went exactly, but there were a few similar methods (assertItemsEqual, assertSameElements, assertCountEqual).  In 3.x we eventually decide to remove the first 2 because it wasn't clear what they were doing, and only assertCountEqual survived.  In 2.7 this wasn't possible, so assertItemsEqual survived.
assertDictContainsSubset is another method that was in 2.7 but is not in 3.x anymore.
Do you think the docs for 2.x should mention this?
msg188047 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-04-29 08:33
I do think this should be mentioned in the 2.7 docs, assertDictContainsSubset is mentioned as "deprecated since 3.2" in the 2.7 docs.  The only problem with that is that there doesn't seem to be a "versionremoved" directive in sphinx, the best alternative seems to be deprecated-removed.

I'm not to happy about the removal though, assertCountEqual is not in 2.7 which means it is unnecessarily hard to port tests from 2.7 to 3.3. I also don't quite understand the difference between assertCountEqual and assetItemsEqual, the documentation for the two (in the 3.3 and 2.7 docs) appears to indicate they have the same behavior (both assert that two sequence have the same contents when the order of items is ignored).
msg188049 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-04-29 08:40
I think they might actually be the same (i.e. the name changed but not the implementation).  See #10242.
If this is true the new name could be mentioned in 2.7.
msg188051 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-04-29 08:59
You're right, according to #10242 the method was renamed in 3.2.

Something like the attached patch?

I'm somewhat flabbergasted that #10242 came to the conclusion that it would be a good idea to rename this method, given the folks that contributed the discussion.   It not that the new name is very good, I've seen it in the 3.3 docs and didn't notice that it was relevant for what I was trying to do until you mentioned the method and I actually read the description. When I first saw the method I thought it was related to list.count.
msg188052 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-04-29 09:08
Apparently assertItemsEqual was added to 2.7 and 3.2 and, after the release of 2.7 but before the release of 3.2, assertItemsEqual has been renamed assertCountEqual (596239da3db7) and initially the assertItemsEqual was available too.  However, since the method was new in 3.2 the old alias got removed shortly after (bdd57841f5e2).  Eventually 3.2 was released with only assertCountEqual.
msg188053 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-04-29 09:19
Looks like we wrote a similar patch at the same time :)
We don't usually use versionchanged in the 2.x docs for things that changed in 3.x.  Using "named" instead of "renamed" is better, since in 3.x the name was assertCountEqual since the beginning, however saying "In Python 3.2" might be confusing (people might think that it's different for 3.3+).  I suggest to replace it with simply "Python 3", or perhaps "Python 3.2+".
msg188054 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2013-04-29 09:22
Your patch looks good.
msg188055 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-29 09:26
New changeset d9921cb6e3cd by Ezio Melotti in branch '2.7':
#17866: mention that in Python 3, assertItemsEqual is named assertCountEqual.
msg188056 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-04-29 09:27
msg265888 - (view) Author: Vitaly (vitaly) Date: 2016-05-19 20:02
Python 2.7 documentation is VERY misleading about the functionality of assertItemsEqual. It actually claims to compare not only the counts, but the actual sorted elements themselves. This documentation mislead my group to use this method for comparing the elements. See

   .. method:: assertItemsEqual(actual, expected, msg=None)

      Test that sequence *expected* contains the same elements as *actual*,
      regardless of their order. When they don't, an error message listing the
      differences between the sequences will be generated.

      Duplicate elements are *not* ignored when comparing *actual* and
      *expected*. It verifies if each element has the same count in both
      sequences. It is the equivalent of ``assertEqual(sorted(expected),
      sorted(actual))`` but it works with sequences of unhashable objects as
msg265890 - (view) Author: Vitaly (vitaly) Date: 2016-05-19 20:10
I opened regarding the erroneous documentation of assertItemsEqual in python 2.7.
msg265979 - (view) Author: Vitaly (vitaly) Date: 2016-05-20 23:50
Folks, assertCountEqual sounds like a really bad name. It misleads users into thinking that it only compares the number of elements in each sequence, whereas it actually asserts that equivalent items are present in both sequences, regardless of order. The original name from 2.7 assertItemsEqual was so much better and more meaningful.
msg266143 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-05-23 13:11
At the time I wanted it to be named assertCountsEqual, which is better (IMO) than either assertItemsEqual or assertCountEqual.  I lost that naming contest, though :(.  On the third hand, I don't think there exists a good two word name for what the function does.
Date User Action Args
2022-04-11 14:57:45adminsetgithub: 62066
2016-05-23 13:11:38r.david.murraysetnosy: + r.david.murray
messages: + msg266143
2016-05-20 23:50:16vitalysetmessages: + msg265979
2016-05-19 20:10:34vitalysetmessages: + msg265890
2016-05-19 20:02:32vitalysetnosy: + vitaly
messages: + msg265888
2013-04-29 09:27:15ezio.melottisetstatus: open -> closed

assignee: docs@python -> ezio.melotti
components: - Library (Lib)
versions: + Python 2.7, - Python 3.3, Python 3.4
resolution: fixed
messages: + msg188056
stage: resolved
2013-04-29 09:26:13python-devsetnosy: + python-dev
messages: + msg188055
2013-04-29 09:22:46ronaldoussorensetmessages: + msg188054
2013-04-29 09:19:46ezio.melottisetfiles: + issue17866-2.diff

messages: + msg188053
2013-04-29 09:08:55ezio.melottisetfiles: + issue17866.diff
keywords: + patch
messages: + msg188052
2013-04-29 08:59:55ronaldoussorensetfiles: + issue17866.txt

messages: + msg188051
2013-04-29 08:40:28ezio.melottisetmessages: + msg188049
2013-04-29 08:37:01floxsetnosy: + flox
2013-04-29 08:33:18ronaldoussorensetmessages: + msg188047
2013-04-29 08:15:18ezio.melottisetnosy: + docs@python, ezio.melotti
messages: + msg188046

assignee: docs@python
components: + Documentation
type: enhancement
2013-04-29 08:01:28ronaldoussorencreate