My proposed solution is like this. It's very unlikely that all 10 items
generated with order_by("?") are the same.
{{{
def test_random_ordering(self):
"""
Use '?' to order randomly.
"""
articles = []
# Iterate 10 times, items in result set shouldn't be all the same
for _ in range(10):
articles.append(list(Article.objects.order_by("?")))
self.assertNotEqual(articles.count(articles[0]), 10)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33762>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Sicong
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33762#comment:1>
* status: assigned => closed
* resolution: => wontfix
* component: Testing framework => Core (Other)
Comment:
> It's very unlikely that all 10 items generated with order_by("?") are
the same.
Unfortunately, it's still possible. I don't see much value in adding a
non-deterministic flaky test.
--
Ticket URL: <https://code.djangoproject.com/ticket/33762#comment:2>