[issue38240] assertCountEqual is horribly misleading, sounds like only counts are being compared

Vitaly Kruglikov report at bugs.python.org
Sat Sep 5 16:17:41 EDT 2020


Vitaly Kruglikov <vitaly.krug at gmail.com> added the comment:

Well, when you do tab-completion in unit tests on `self.` and
`assertCountEqual` pops up, it sure sounds a lot like it's going to compare
just the count of the items. The point is that the name of the function is
not self-documenting, hence "misleading".

A better name could be `assertItemsEqual` or `assertCountAndItemsEqual`

On Sat, Sep 5, 2020 at 1:02 PM Raymond Hettinger <report at bugs.python.org>
wrote:

>
> Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
>
> This should stay closed as a duplicate.
>
> If you must, reopen of the original 27071, but it was closed for a
> reason.  The majority of respondents voted for the status quo.  Each
> alternative that was considered had its own share of problems.
>
> BTW, it is hyperbolic to call the name "horribly misleading".  The method
> literally runs Counter and checks for equality.  The docstring is clear
> about this:
>
>     def assertCountEqual(self, first, second, msg=None):
>         """Asserts that two iterables have the same elements, the same
> number of
>         times, without regard to order.
>
>             self.assertEqual(Counter(list(first)),
>                              Counter(list(second)))
>
>          Example:
>             - [0, 1, 1] and [1, 0, 1] compare equal.
>             - [0, 0, 1] and [0, 1] compare unequal.
>
>         """
>
> ----------
> nosy: +rhettinger
> status: open -> closed
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <https://bugs.python.org/issue38240>
> _______________________________________
>

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38240>
_______________________________________


More information about the Python-bugs-list mailing list