Skip to content

Commit 489230a

Browse files
authored
Attempt at handling random testFileTimes test failure in test_win32file.py (#2346)
1 parent 01e16ee commit 489230a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

win32/test/test_win32file.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,25 @@ def testFileTimes(self):
227227
)
228228
try:
229229
ct, at, wt = win32file.GetFileTime(f)
230-
self.assertTrue(
231-
ct >= now,
230+
# NOTE (Avasam): I've seen the time be off from -0.003 to +1.11 seconds,
231+
# so the above comment about microseconds might be wrong.
232+
# Let's standardize ms and avoid random CI failures
233+
# https://github.com/mhammond/pywin32/issues/2203
234+
ct = ct.replace(microsecond=0)
235+
at = at.replace(microsecond=0)
236+
wt = wt.replace(microsecond=0)
237+
self.assertGreaterEqual(
238+
ct,
239+
now,
232240
f"File was created in the past - now={now}, created={ct}",
233241
)
234-
self.assertTrue(now <= ct <= nowish, (now, ct))
235-
self.assertTrue(
236-
wt >= now,
242+
self.assertTrue(now <= ct <= nowish, (now, ct, nowish))
243+
self.assertGreaterEqual(
244+
wt,
245+
now,
237246
f"File was written-to in the past now={now}, written={wt}",
238247
)
239-
self.assertTrue(now <= wt <= nowish, (now, wt))
248+
self.assertTrue(now <= wt <= nowish, (now, wt, nowish))
240249

241250
# Now set the times.
242251
win32file.SetFileTime(f, later, later, later, UTCTimes=True)

0 commit comments

Comments
 (0)