Skip to content

Commit a371690

Browse files
committed
fix flaky test: model_fields_.test_embedded_model.ModelTests.test_pre_save
1 parent 10710bc commit a371690

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tests/model_fields_/test_embedded_model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import operator
2+
from datetime import timedelta
23

34
from django.core.exceptions import FieldDoesNotExist, ValidationError
45
from django.db import models
@@ -74,7 +75,9 @@ def test_pre_save(self):
7475
obj = Holder.objects.create(data=Data())
7576
auto_now = truncate_ms(obj.data.auto_now)
7677
auto_now_add = truncate_ms(obj.data.auto_now_add)
77-
self.assertEqual(auto_now, auto_now_add)
78+
# auto_now and auto_now_add may differ by a millisecond since they
79+
# aren't generated simultaneously.
80+
self.assertAlmostEqual(auto_now, auto_now_add, delta=timedelta(microseconds=1000))
7881
# save() updates auto_now but not auto_now_add.
7982
obj.save()
8083
self.assertEqual(truncate_ms(obj.data.auto_now_add), auto_now_add)

0 commit comments

Comments
 (0)