It turns out that with os/python/C buffering, we need to flush Make the test compatibily with filesystems that only have 1s resolution. Also, it seems on my Linux machine, .writelines() leaves data in buffers that doesn't get written out until .close(). But that messes up the timestamps. So now we call flush before we close.