Skip to content
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

Fixed unclosed file warning in test_imageshow.py #8446

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

radarhere
Copy link
Member

https://github.com/python-pillow/Pillow/actions/runs/11202062547/job/31137725975#step:12:4820

Tests/test_imageshow.py::test_ipythonviewer
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/_pytest/python.py:159: ResourceWarning: unclosed file <_io.BufferedReader name='/Users/runner/work/Pillow/Pillow/Tests/images/hopper.ppm'>

The file is opened in hopper()

Pillow/Tests/helper.py

Lines 252 to 261 in 27c1bb2

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")

and then called in

im = hopper()
assert test_viewer.show(im) == 1

Adding a context manager fixes the warning.

@radarhere radarhere changed the title Fixed unclosed file warning in test_imageshow Fixed unclosed file warning in test_imageshow.py Oct 7, 2024
@hugovk hugovk merged commit f5ce8a9 into python-pillow:main Oct 7, 2024
46 of 47 checks passed
@radarhere radarhere deleted the close branch October 7, 2024 09:17
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