Skip to content

Commit

Permalink
Attempt at handling random testFileTimes test failure in `test_win3…
Browse files Browse the repository at this point in the history
…2file.py` (#2346)
  • Loading branch information
Avasam authored Oct 13, 2024
1 parent 01e16ee commit 489230a
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions win32/test/test_win32file.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,25 @@ def testFileTimes(self):
)
try:
ct, at, wt = win32file.GetFileTime(f)
self.assertTrue(
ct >= now,
# NOTE (Avasam): I've seen the time be off from -0.003 to +1.11 seconds,
# so the above comment about microseconds might be wrong.
# Let's standardize ms and avoid random CI failures
# https://github.com/mhammond/pywin32/issues/2203
ct = ct.replace(microsecond=0)
at = at.replace(microsecond=0)
wt = wt.replace(microsecond=0)
self.assertGreaterEqual(
ct,
now,
f"File was created in the past - now={now}, created={ct}",
)
self.assertTrue(now <= ct <= nowish, (now, ct))
self.assertTrue(
wt >= now,
self.assertTrue(now <= ct <= nowish, (now, ct, nowish))
self.assertGreaterEqual(
wt,
now,
f"File was written-to in the past now={now}, written={wt}",
)
self.assertTrue(now <= wt <= nowish, (now, wt))
self.assertTrue(now <= wt <= nowish, (now, wt, nowish))

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

0 comments on commit 489230a

Please sign in to comment.