@@ -452,19 +452,37 @@ def decorator(func):
452
452
453
453
_ , result_dir = map (Path , _image_directories (func ))
454
454
455
- @pytest .mark .parametrize ("ext" , extensions )
456
- def wrapper (ext ):
457
- fig_test = plt .figure ("test" )
458
- fig_ref = plt .figure ("reference" )
459
- func (fig_test , fig_ref )
460
- test_image_path = str (
461
- result_dir / (func .__name__ + "." + ext ))
462
- ref_image_path = str (
463
- result_dir / (func .__name__ + "-expected." + ext ))
464
- fig_test .savefig (test_image_path )
465
- fig_ref .savefig (ref_image_path )
466
- _raise_on_image_difference (
467
- ref_image_path , test_image_path , tol = tol )
455
+ if len (inspect .signature (func ).parameters ) == 2 :
456
+ # Free-standing function.
457
+ @pytest .mark .parametrize ("ext" , extensions )
458
+ def wrapper (ext ):
459
+ fig_test = plt .figure ("test" )
460
+ fig_ref = plt .figure ("reference" )
461
+ func (fig_test , fig_ref )
462
+ test_image_path = str (
463
+ result_dir / (func .__name__ + "." + ext ))
464
+ ref_image_path = str (
465
+ result_dir / (func .__name__ + "-expected." + ext ))
466
+ fig_test .savefig (test_image_path )
467
+ fig_ref .savefig (ref_image_path )
468
+ _raise_on_image_difference (
469
+ ref_image_path , test_image_path , tol = tol )
470
+
471
+ elif len (inspect .signature (func ).parameters ) == 3 :
472
+ # Method.
473
+ @pytest .mark .parametrize ("ext" , extensions )
474
+ def wrapper (self , ext ):
475
+ fig_test = plt .figure ("test" )
476
+ fig_ref = plt .figure ("reference" )
477
+ func (self , fig_test , fig_ref )
478
+ test_image_path = str (
479
+ result_dir / (func .__name__ + "." + ext ))
480
+ ref_image_path = str (
481
+ result_dir / (func .__name__ + "-expected." + ext ))
482
+ fig_test .savefig (test_image_path )
483
+ fig_ref .savefig (ref_image_path )
484
+ _raise_on_image_difference (
485
+ ref_image_path , test_image_path , tol = tol )
468
486
469
487
return wrapper
470
488
0 commit comments