How do I test Django QuerySets are equal?

By default assertQuerysetEqual uses repr() on the first argument. This is why you were having issues with the strings in the queryset comparison.

To work around this you can override the transform argument with a lambda function that doesn’t use repr():

self.assertQuerysetEqual(queryset_1, queryset_2, transform=lambda x: x)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)