#33762: test_random_ordering not really testing randomization
------------------------------------------------+------------------------
Reporter: Sicong | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Testing framework | Version:
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
Unit test
[https://github.com/django/django/blob/6f73eb9d90cfec684529aab48d517e3d6449ba8c/tests/ordering/tests.py#L235
test_random_ordering] only checks the length of result queryset. It's not
checking if order_by("?") giving same result every time.
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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018121d5328b-c33583b2-2f2b-4e86-b2c0-735f67d64766-000000%40eu-central-1.amazonses.com.