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.

Author steven.daprano
Recipients EmilBode, steven.daprano
Date 2020-06-08.12:40:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1591620045.33.0.195129071233.issue40909@roundup.psfhosted.org>
In-reply-to
Content
This is working as designed. assertCountEqual is documented here:

https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertCountEqual

It says: "Test that sequence *first* contains the same elements as *second*..." notice that it talks about *sequences*, not mappings. The (approximate) equivalent code is also given:

    assertEqual(Counter(list(first)), Counter(list(second)))

If the arguments are dicts, only the keys are compared. The example you give correctly passes, because it is equivalent to calling `assertCountEqual(first.keys(), second.keys())` and the keys are equal.

If you want to compare the items, you can call `assertCountEqual(first.items(), second.items())`.

The example comparing lists correctly fails because the list elements are different.
History
Date User Action Args
2020-06-08 12:40:45steven.dapranosetrecipients: + steven.daprano, EmilBode
2020-06-08 12:40:45steven.dapranosetmessageid: <1591620045.33.0.195129071233.issue40909@roundup.psfhosted.org>
2020-06-08 12:40:45steven.dapranolinkissue40909 messages
2020-06-08 12:40:45steven.dapranocreate