Fixed unclosed file warning by radarhere · Pull Request #8847 · python-pillow/Pillow

Skip to content

Navigation Menu

Sign in

Appearance settings

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Conversation

@radarhere

Copy link Copy Markdown

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

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@radarhere @hugovk