11import io
2+ import warnings
23
34import numpy as np
45from numpy .testing import assert_array_almost_equal
1718from matplotlib .transforms import IdentityTransform
1819
1920
21+ def require_pillow_feature (name ):
22+ with warnings .catch_warnings ():
23+ warnings .simplefilter ('ignore' )
24+ available = features .check (name .lower ())
25+ return pytest .mark .skipif (not available , reason = f"{ name } support not available" )
26+
27+
2028def test_repeated_save_with_alpha ():
2129 # We want an image which has a background color of bluish green, with an
2230 # alpha of 0.25.
@@ -249,7 +257,7 @@ def test_pil_kwargs_tiff():
249257 assert tags ["ImageDescription" ] == "test image"
250258
251259
252- @pytest . mark . skipif ( not features . check ( "webp" ), reason = " WebP support not available" )
260+ @require_pillow_feature ( ' WebP' )
253261def test_pil_kwargs_webp ():
254262 plt .plot ([0 , 1 , 2 ], [0 , 1 , 0 ])
255263 buf_small = io .BytesIO ()
@@ -263,7 +271,7 @@ def test_pil_kwargs_webp():
263271 assert buf_large .getbuffer ().nbytes > buf_small .getbuffer ().nbytes
264272
265273
266- @pytest . mark . skipif ( not features . check ( "avif" ), reason = " AVIF support not available" )
274+ @require_pillow_feature ( ' AVIF' )
267275def test_pil_kwargs_avif ():
268276 plt .plot ([0 , 1 , 2 ], [0 , 1 , 0 ])
269277 buf_small = io .BytesIO ()
@@ -295,7 +303,7 @@ def test_gif_alpha():
295303 assert im .info ["transparency" ] < len (im .palette .colors )
296304
297305
298- @pytest . mark . skipif ( not features . check ( "webp" ), reason = " WebP support not available" )
306+ @require_pillow_feature ( ' WebP' )
299307def test_webp_alpha ():
300308 plt .plot ([0 , 1 , 2 ], [0 , 1 , 0 ])
301309 buf = io .BytesIO ()
@@ -304,7 +312,7 @@ def test_webp_alpha():
304312 assert im .mode == "RGBA"
305313
306314
307- @pytest . mark . skipif ( not features . check ( "avif" ), reason = " AVIF support not available" )
315+ @require_pillow_feature ( ' AVIF' )
308316def test_avif_alpha ():
309317 plt .plot ([0 , 1 , 2 ], [0 , 1 , 0 ])
310318 buf = io .BytesIO ()
0 commit comments