os.path.setmtime ?

R

Richard Wesley

I am trying to set the mod date on a file (Linux) as part of a unit test
run. I can just wait one second, but that slows the test down. A
better solution would be to tweak the mod date on a file, but os.path
does not seem to have setmtime.

Is there any simple way to do this?

TIA,
 
H

Holger Krekel

Richard said:
I am trying to set the mod date on a file (Linux) as part of a unit test
run. I can just wait one second, but that slows the test down. A
better solution would be to tweak the mod date on a file, but os.path
does not seem to have setmtime.

Is there any simple way to do this?

it is spelled

os.utime

in python.

os.utime(path, None)

will set a/mtime to current time and

os.utime (path, (-1, newtime))

will set mtime to newtime. Note, however, that the effects and the
actual time resolution of this call are very platform independant.

cheers,

holger
 
R

Richard Wesley

Holger Krekel said:
it is spelled

os.utime

Thanks, that did the trick. Saves me 2-3 seconds per test.
in python.

os.utime(path, None)

will set a/mtime to current time and

os.utime (path, (-1, newtime))

will set mtime to newtime. Note, however, that the effects and the
actual time resolution of this call are very platform independant.

I am making relative changes under Linux, so this is pretty well
controlled.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,448
Latest member
DeanaQ4445

Latest Threads

Top