Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions test/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,16 @@ def test_preserve_times(self):
# HERE an external access to the file is possible, modifying its access time

# read times again and compare with original
st = os.stat(self.file.filename)
max_tries = 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment here explaining why this is necessary. This is so weird that we need to document it somehow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to understand why it happens first.
Fixing the test is perhaps not enough...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

while max_tries:
self._read_testfile() # required
st = os.stat(self.file.filename)
if st.st_atime_ns > 0:
break
max_tries -= 1

self.assertTrue(max_tries > 0, "Max attempts to os.stat() attained!")

(after_atime_ns, after_mtime_ns) = (st.st_atime_ns, st.st_mtime_ns)

# on macOS 10.14 and later os.utime only sets the times with second
Expand All @@ -172,7 +181,7 @@ def test_preserve_times(self):
# access times may not be equal
# time difference should be positive and reasonably low (if no access in between, it should be 0)
delta = after_atime_ns - before_atime_ns
tolerance = 10**7 # 0.01 seconds
tolerance = 10**8 # 0.1 seconds
self.assertTrue(0 <= delta < tolerance, "0 <= %s < %s" % (delta, tolerance))

# ensure written data can be read back
Expand Down
Loading