From b5371539a9d871758d639a85d1f2fd648c1f633d Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 30 Jun 2020 13:08:23 +0200 Subject: [PATCH] Fixed #31752 -- Fixed intermittent test_order_by_relational_field_through_model failure. Set explicit datetime for M2M ordering test. Thanks to Mariusz Felisiak for the suggestion. --- tests/m2m_through/tests.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/m2m_through/tests.py b/tests/m2m_through/tests.py index dd40e9760c5..ec3c481dd23 100644 --- a/tests/m2m_through/tests.py +++ b/tests/m2m_through/tests.py @@ -1,4 +1,4 @@ -from datetime import date, datetime +from datetime import date, datetime, timedelta from operator import attrgetter from django.db import IntegrityError @@ -238,10 +238,12 @@ class M2mThroughTests(TestCase): ) def test_order_by_relational_field_through_model(self): - CustomMembership.objects.create(person=self.jim, group=self.rock) - CustomMembership.objects.create(person=self.bob, group=self.rock) - CustomMembership.objects.create(person=self.jane, group=self.roll) - CustomMembership.objects.create(person=self.jim, group=self.roll) + today = datetime.now() + yesterday = today - timedelta(days=1) + CustomMembership.objects.create(person=self.jim, group=self.rock, date_joined=yesterday) + CustomMembership.objects.create(person=self.bob, group=self.rock, date_joined=today) + CustomMembership.objects.create(person=self.jane, group=self.roll, date_joined=yesterday) + CustomMembership.objects.create(person=self.jim, group=self.roll, date_joined=today) self.assertSequenceEqual( self.rock.custom_members.order_by('custom_person_related_name'), [self.jim, self.bob]