Re-opening NamedTemporaryFile is not valid on Windows #222
Labels
BUG
This is a bug, not a feature request; something isn't working.
P1
High priority, not breaking but hindering or lessening existing functionality
portability
Component: Portability issues
Original report by Jeff Brantley (Bitbucket: jsbmsu, GitHub: jsbmsu).
Both test and production code are using
tempfile.NamedTemporaryFile
, which on non-Windows can be re-opened (by name) while the original handle is still open. For example,beancount.utils.test_utils.docfile
decorator extracts a test's docstring, writes it to a file, and then---still holding the file open---passes the filename to the test, to be read by that test.Searching the repo for NamedTemporaryFile turns up 10 files with "test" in the name, as well as
beancount.parser.lexer
andbeancount.utils.text_utils
.It's unfortunate that this doesn't just work. Assuming all instances are in a
with
statement (not true, but perhaps that is a bug?), then it may be possible to workaround with a wrapper that passesdelete=False
and then manually deletes the file on__exit__
. I'm not sure what flaws (if any) this may exhibit over the real thing.The text was updated successfully, but these errors were encountered: