[Django] #32469: Add support for maxDiff to TransactionTestCase.assertQuerysetEqual().

29 views
Skip to first unread message

Django

unread,
Feb 21, 2021, 10:36:27 AM2/21/21
to django-...@googlegroups.com
#32469: Add support for maxDiff to TransactionTestCase.assertQuerysetEqual().
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: New | Status: assigned
feature |
Component: Testing | Version: master
framework | Keywords: maxDiff,
Severity: Normal | assertQuerysetEqual
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
`TransactionTestCase.assertQuerysetEqual()` does not respect `maxDiff`
when `ordered=False`.

So it turns out that although `assertQuerySet()` with `ordered=False`
compares two instances of `collection.Counter()` - a subclass of `dict` -
calling `assertEqual()` will not defer to `assertDictEqual()` and so
`maxDiff` isn't supported. We should use `assertDictEqual()` explicitly.

See the following links for details:

-
https://docs.python.org/3/library/unittest.html#unittest.TestCase.maxDiff
-
https://github.com/python/cpython/blob/d5fc99873769f0d0d5c5d5d99059177a75a4e46e/Lib/unittest/case.py#L809-L818

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

Django

unread,
Feb 21, 2021, 10:43:10 AM2/21/21
to django-...@googlegroups.com
#32469: Add support for maxDiff to TransactionTestCase.assertQuerysetEqual().
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: New feature | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: maxDiff, | Triage Stage:
assertQuerysetEqual | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14027 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32469#comment:1>

Django

unread,
Feb 21, 2021, 3:46:28 PM2/21/21
to django-...@googlegroups.com
#32469: Add support for maxDiff to TransactionTestCase.assertQuerysetEqual().
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: New feature | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: maxDiff, | Triage Stage: Accepted
assertQuerysetEqual |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/32469#comment:2>

Django

unread,
Feb 22, 2021, 3:31:38 AM2/22/21
to django-...@googlegroups.com
#32469: Add support for maxDiff to TransactionTestCase.assertQuerysetEqual().
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |

Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: maxDiff, | Triage Stage: Ready for
assertQuerysetEqual | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* type: New feature => Cleanup/optimization
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32469#comment:3>

Django

unread,
Feb 22, 2021, 4:05:55 AM2/22/21
to django-...@googlegroups.com
#32469: Add support for maxDiff to TransactionTestCase.assertQuerysetEqual().
-------------------------------------+-------------------------------------
Reporter: Nick Pope | Owner: Nick Pope
Type: | Status: closed

Cleanup/optimization |
Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed

Keywords: maxDiff, | Triage Stage: Ready for
assertQuerysetEqual | checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"0e4e35722a03d2e4cb0b993f9b167103928b3199" 0e4e3572]:
{{{
#!CommitTicketReference repository=""
revision="0e4e35722a03d2e4cb0b993f9b167103928b3199"
Fixed #32469 -- Made assertQuerysetEqual() respect maxDiff when
ordered=False.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32469#comment:4>

Reply all
Reply to author
Forward
0 new messages