[Numpy-discussion] Handling named temporary files in tests

David Cournapeau david at ar.media.kyoto-u.ac.jp
Mon Mar 9 05:47:59 EDT 2009


Hi,

    While fixing several windows specific unit test failures, I
encountered some problems I am not sure how to solve. In particular, we
have a relatively common idiom as follows:

Open file securely with a visible name (using NamedTemporaryFile)
write some content into it
open the file with another open call

Of course, this does not work on windows. NamedTemporaryFile is
basically useless on this platform (windows refuses to let a process to
reopen a file opened from NamedTemporaryFile). I can see two solutions:
 - using mkstemp + re-opening the file later from the name returned by
mkstemp: AFAICT, this basically defeats the whole purpose of mkstemp
 - have our own layer to bypass mkstemp on windows, where security is
not a concern anyway, and use the proper functions on sane platforms.

Do people have an opinion on this ? Or maybe a solution to the problem
altogether ?

cheers,

David



More information about the NumPy-Discussion mailing list