Fixed unclosed file warning in test_imageshow.py by radarhere · Pull Request #8446 · python-pillow/Pillow

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

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.