TST: fix PermissionError on Windows#5278
TST: fix PermissionError on Windows#5278cgohlke wants to merge 2 commits intomatplotlib:masterfrom cgohlke:patch-16
Conversation
There was a problem hiding this comment.
From docs:
If delete is true (the default), the file is deleted as soon as it is closed.
That sounds like the temporary file would be cleaned up here. Then the write in the next line will be to a file that isn't cleaned up. Or does the context manager try to delete the file again even though it's been closed already?
Since json_load/json_dump are new, maybe they should be modified to take a file object instead?
There was a problem hiding this comment.
+1 on modifying json_load/json_dump.
There was a problem hiding this comment.
I don't really care how to resolve this, but we should confirm that this doesn't leave a file hanging around on disk, which is what I think this change does.
There was a problem hiding this comment.
This should be in a try/finally so it always runs.
There was a problem hiding this comment.
sigh... we are making this overly complicated.
try:
temp = tempfile.NamedTemporaryFile(delete=False)
temp.close()
json_dump(fontManager, temp.name)
copy = json_load(temp.name)
finally:
if os.path.exists(temp.name):
os.remove(temp.name)
|
@cgohlke: Did you close this by accident? |
|
Included a version of this PR in #5604 |
On Windows, a open NamedTemporaryFile can not be used to open the file a second time.
Fixes one test error: