Opened 5 years ago

Closed 4 years ago

Last modified 3 years ago

#31235 closed New feature (fixed)

assertQuerysetEqual cannot compare querysets directly.

Reported by: Peter Inglesby Owned by: Hasan Ramezani
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

As discussed briefly on django-dev [0] I'd like to modify assertQuerysetEqual so that assertQuerysetEqual(qs1, qs2) works.

[0] https://groups.google.com/forum/?#!msg/django-developers/wdO0e0835EY/X_D9gVe_EwAJ

Change History (11)

comment:1 by Simon Charette, 5 years ago

Triage Stage: UnreviewedAccepted

I think the suggested approach makes sense, I suggest we deprecate the repr default entirely through a deprecation period.

comment:2 by Mariusz Felisiak, 5 years ago

Has patch: set
Owner: changed from nobody to Peter Inglesby
Patch needs improvement: set
Status: newassigned
Summary: assertQuerysetEqual cannot compare querysets directlyassertQuerysetEqual cannot compare querysets directly.
Version: 3.0master

comment:3 by Hasan Ramezani, 4 years ago

Owner: changed from Peter Inglesby to Hasan Ramezani
Patch needs improvement: unset

comment:4 by Mariusz Felisiak, 4 years ago

Patch needs improvement: set

comment:5 by Hasan Ramezani, 4 years ago

Mariusz:
I rebased the PR and changed a lot of assertions and remove repr from assertQuerysetEqual.
There are some assertions that are using repr. most of them are for models that use more than one field in __str__.

like:

I think we can keep them as is. what do you think?

comment:6 by Hasan Ramezani, 4 years ago

Patch needs improvement: unset

comment:7 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 3f7b327:

Fixed #31235 -- Made assertQuerysetEqual() compare querysets directly.

This also replaces assertQuerysetEqual() to
assertSequenceEqual()/assertCountEqual() where appropriate.

Co-authored-by: Peter Inglesby <peter.inglesby@…>
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@…>

comment:9 by GitHub <noreply@…>, 4 years ago

In bc43ae7:

Refs #31235 -- Improved assertQuerysetEqual() warning message with stacklevel=2.

comment:10 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 104d6172:

[3.2.x] Refs #31235 -- Improved assertQuerysetEqual() warning message with stacklevel=2.

Backport of bc43ae7c13b903022ec1fcb4867f5f10d7f125d6 from main

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In e2be307:

Refs #31235 -- Made assertQuerysetEqual() not call repr() on a queryset when compared to string values.

Per deprecation timeline.

Note: See TracTickets for help on using tickets.
Back to Top