Skip to content

Fixed unclosed file warning #8847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2025
Merged

Conversation

radarhere
Copy link
Member

Pillow/Tests/test_image.py

Lines 232 to 236 in 60b5131

def test_unknown_extension(self, tmp_path: Path) -> None:
im = hopper()
temp_file = tmp_path / "temp.unknown"
with pytest.raises(ValueError):
im.save(temp_file)

raises an unclosed file warning - https://github.com/python-pillow/Pillow/actions/runs/14155530774/job/39654267057?pr=8844#step:6:5623

This is because hopper() is just returning an opened image.

Pillow/Tests/helper.py

Lines 248 to 257 in 60b5131

def hopper(mode: str | None = None) -> Image.Image:
# Use caching to reduce reading from disk, but return a copy
# so that the cached image isn't modified by the tests
# (for fast, isolated, repeatable tests).
if mode is None:
# Always return fresh not-yet-loaded version of image.
# Operations on not-yet-loaded images are a separate class of errors
# that we should catch.
return Image.open("Tests/images/hopper.ppm")

@hugovk hugovk merged commit 81be8d5 into python-pillow:main Mar 30, 2025
54 checks passed
@radarhere radarhere deleted the unclosed_file branch March 30, 2025 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants