unittest.assertCountEqual naming is confuse

unittest.assertCountEqual (unittest — Unit testing framework — Python 3.9.1 documentation)

I think that this method naming is confuse.

Because this naming look like validate count.

So I want to propose. this method naming change that assertListElementEqual.

thank you.

That method name has existed since Python 3.2.0 which is a decade old come next month. Changing its name would break too much code. The best you could get is an aliased name. But for me, the alternative name you suggested of assertListElementalEqual() doesn’t communicate what it does either as I feel like the proposed name says a list is being checked per-element which still suggests order.

I agree with Brett.

It’s a pity that we didn’t name the method assertCountsEqual (note the
use of plural counts). The singular name suggests:

  • a count (which one?) is equal

while the plural suggests:

  • all counts are equal

which is the actual behaviour.

Perhaps we could rename the method to the plural, and immediately add an
alias with the former name and depreciate the alias. That is:

  • the preferred spelling becomes assertCountsEqual;

  • old spelling remains for backwards combatibility, but deprecated.

Is it worth is? shrug I don’t know. If this was a spelling error in
the documentation, I would say “just fix it” but (alleged) spelling
errors in APIs are a different story.

1 Like

I like this plan (rename, alias, and deprecate) even if the deprecation is in documentation only. I also had no clue what the method should be doing, and even after learning it would not remember.

I think assertCountsEqual is a much better reminder.

See also Issue 27071: unittest.TestCase.assertCountEqual is a very misleading name - Python tracker which contains a discussion on possible alternative names.