Skip to content

fix: use delete=False for NamedTemporaryFile in tests on Windows#677

Open
athifmuhammad1001-svg wants to merge 2 commits into
ollama:mainfrom
athifmuhammad1001-svg:fix/windows-namedtempfile
Open

fix: use delete=False for NamedTemporaryFile in tests on Windows#677
athifmuhammad1001-svg wants to merge 2 commits into
ollama:mainfrom
athifmuhammad1001-svg:fix/windows-namedtempfile

Conversation

@athifmuhammad1001-svg

Copy link
Copy Markdown

Fixes #676 tests failing on Windows due to NamedTemporaryFile locking.

On Windows, NamedTemporaryFile locks the file while open, causing
PermissionError when the code tries to read it. Adding delete=False
resolves this.

Fixes: 8 failing tests on Windows

  • test_client_generate_images
  • test_client_create_blob
  • test_client_create_blob_exists
  • test_async_client_generate_images
  • test_async_client_create_blob
  • test_async_client_create_blob_exists
  • test_image_serialization_path
  • test_image_serialization_string_path

@aglpy

aglpy commented Jun 10, 2026

Copy link
Copy Markdown

This fix solves the Windows issue, but since delete=False is used, the temp image files won’t be deleted automatically and may be left on disk.

Maybe it would be better to wrap this in a try/finally block and remove the file manually after it has been used.

Don’t you think?

@athifmuhammad1001-svg

Copy link
Copy Markdown
Author

This fix solves the Windows issue, but since delete=False is used, the temp image files won’t be deleted automatically and may be left on disk.

Maybe it would be better to wrap this in a try/finally block and remove the file manually after it has been used.

Don’t you think?

Thanks for the insight! You were right, the temp files would remain on the disk when delete=False is used. I used os.remove() to explicitly remove those temp files using the try/except block in case of FileNotFoundError. I verified that the temp files do not remain on the disk after the changes were made. Pushed the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests fail on Windows due to NamedTemporaryFile locking behavior

2 participants