python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.32k stars 2.23k forks source link

Fixed unclosed file warning in test_imageshow.py #8446

Closed radarhere closed 1 month ago

radarhere commented 1 month ago

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() https://github.com/python-pillow/Pillow/blob/27c1bb265432cb5a1138e39165f0610e2d8a4e94/Tests/helper.py#L252-L261

and then called in https://github.com/python-pillow/Pillow/blob/27c1bb265432cb5a1138e39165f0610e2d8a4e94/Tests/test_imageshow.py#L120-L121

Adding a context manager fixes the warning.