From 787cf7932dadce415dbf21520264489e1fc037ce Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Mon, 3 Aug 2020 18:47:57 +1000 Subject: [PATCH] Use context managers when opening images Co-authored-by: nulano --- Tests/test_image.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index 6b3148041..40b6dba8d 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -93,21 +93,24 @@ class TestImage: assert len(Image.ID) == 0 for ext in (".jpg", ".png"): with pytest.raises(UnidentifiedImageError): - Image.open("Tests/images/hopper" + ext) + with Image.open("Tests/images/hopper" + ext): + pass # Only JPEG Image.init(["JPEG"]) assert len(Image.ID) != 0 Image.open("Tests/images/hopper.jpg") with pytest.raises(UnidentifiedImageError): - Image.open("Tests/images/hopper.png") + with Image.open("Tests/images/hopper.png"): + pass finally: # All formats Image.init(True) assert len(Image.ID) != 0 for ext in (".jpg", ".png"): - Image.open("Tests/images/hopper" + ext) + with Image.open("Tests/images/hopper" + ext): + pass def test_width_height(self): im = Image.new("RGB", (1, 2))