diff --git a/Tests/test_file_icns.py b/Tests/test_file_icns.py index 7ce8cb286..30ec3dc72 100644 --- a/Tests/test_file_icns.py +++ b/Tests/test_file_icns.py @@ -143,8 +143,8 @@ def test_not_an_icns_file(): def test_icns_decompression_bomb(): - with pytest.raises(Image.DecompressionBombError): - im = Image.open( - "Tests/images/oom-8ed3316a4109213ca96fb8a256a0bfefdece1461.icns" - ) - im.load() + with Image.open( + "Tests/images/oom-8ed3316a4109213ca96fb8a256a0bfefdece1461.icns" + ) as im: + with pytest.raises(Image.DecompressionBombError): + im.load()