Opened 2 years ago
Closed 2 years ago
#33762 closed Cleanup/optimization (wontfix)
test_random_ordering not really testing randomization
Reported by: | Sicong | Owned by: | Sicong |
---|---|---|---|
Component: | Core (Other) | Version: | |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Unit test 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)
Change History (2)
comment:1 by , 2 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 2 years ago
Component: | Testing framework → Core (Other) |
---|---|
Resolution: | → wontfix |
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Unfortunately, it's still possible. I don't see much value in adding a non-deterministic flaky test.