@@ -389,18 +389,22 @@ def decorator(func):
389
389
390
390
@pytest .mark .parametrize ("ext" , extensions )
391
391
def wrapper (* args , ext , ** kwargs ):
392
- fig_test = plt .figure ("test" )
393
- fig_ref = plt .figure ("reference" )
394
- func (* args , fig_test = fig_test , fig_ref = fig_ref , ** kwargs )
395
- test_image_path = result_dir / (func .__name__ + "." + ext )
396
- ref_image_path = result_dir / (
397
- func .__name__ + "-expected." + ext
398
- )
399
- fig_test .savefig (test_image_path )
400
- fig_ref .savefig (ref_image_path )
401
- _raise_on_image_difference (
402
- ref_image_path , test_image_path , tol = tol
403
- )
392
+ try :
393
+ fig_test = plt .figure ("test" )
394
+ fig_ref = plt .figure ("reference" )
395
+ func (* args , fig_test = fig_test , fig_ref = fig_ref , ** kwargs )
396
+ test_image_path = result_dir / (func .__name__ + "." + ext )
397
+ ref_image_path = result_dir / (
398
+ func .__name__ + "-expected." + ext
399
+ )
400
+ fig_test .savefig (test_image_path )
401
+ fig_ref .savefig (ref_image_path )
402
+ _raise_on_image_difference (
403
+ ref_image_path , test_image_path , tol = tol
404
+ )
405
+ finally :
406
+ plt .close (fig_test )
407
+ plt .close (fig_ref )
404
408
405
409
sig = inspect .signature (func )
406
410
new_sig = sig .replace (
0 commit comments