[Django] #33609: Use assertCountEqual in assertQuerysetEqual

34 views
Skip to first unread message

Django

unread,
Mar 30, 2022, 10:01:43 AM3/30/22
to django-...@googlegroups.com
#33609: Use assertCountEqual in assertQuerysetEqual
-------------------------------------+-------------------------------------
Reporter: David | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Testing | Version: dev
framework |
Severity: Normal | Keywords: queryseteuql
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
As of now the assertQueryEqual method
[[https://github.com/django/django/blob/04ad0f26ba4b8c79dc311e1789457e0c4d1b8832/django/test/testcases.py#L1240-L1241|ueses
counters to compare unordered Querysets]], in the standard unittest
package there is already such method called
[[https://docs.python.org/3/library/unittest.html?highlight=assertcountequal#unittest.TestCase.assertCountEqual|assertCountEqual]],
which also has better output-formatting capability.

{{{#!python
self.assertCountEqual(items, values, msg=msg)
}}}

Using data from current test it will output:

{{{
Element counts were not equal:
First has 0, Second has 1: 'Extra Person'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33609>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages