diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index da78e4911..5bd16e356 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -895,8 +895,8 @@ class TestFileJpeg: if buffer: mystdout = mystdout.buffer - reloaded = Image.open(mystdout) - assert_image_equal(reloaded, im_roundtrip) + with Image.open(mystdout) as reloaded: + assert_image_equal(reloaded, im_roundtrip) @pytest.mark.skipif(not is_win32(), reason="Windows only") diff --git a/Tests/test_file_ppm.py b/Tests/test_file_ppm.py index 07c9bda84..ad36319db 100644 --- a/Tests/test_file_ppm.py +++ b/Tests/test_file_ppm.py @@ -108,5 +108,5 @@ def test_save_stdout(buffer): if buffer: mystdout = mystdout.buffer - reloaded = Image.open(mystdout) - assert_image_equal_tofile(reloaded, TEST_FILE) + with Image.open(mystdout) as reloaded: + assert_image_equal_tofile(reloaded, TEST_FILE)