16👍
✅
From docs:
By default, the comparison is also ordering dependent. If qs doesn’t provide an implicit ordering, you can set the ordered parameter to False, which turns the comparison into a collections.Counter comparison. If the order is undefined (if the given qs isn’t ordered and the comparison is against more than one ordered values), a ValueError is raised.
You are comparing a QuerySet
with a list
. List has an ordering but Queryset doesn’t.
So you can either convert QuerySet to list
queryset = vote_form.cleaned_data['choice']
self.assertQuerysetEqual(list(queryset), ['<Choice: First choice>', ...])
or pass ordered=False
to assertQuerysetEqual
.
queryset = vote_form.cleaned_data['choice']
self.assertQuerysetEqual(list(queryset), ['<Choice: First choice>', ...], ordered=False)
Reordering Queryset before comparing should also work.
Source:stackexchange.com