@@ -361,12 +361,11 @@ def compare_image_to_baseline(self, item, fig, result_dir):
361
361
fig .savefig (str (test_image ), ** savefig_kwargs )
362
362
363
363
if not os .path .exists (baseline_image_ref ):
364
- pytest .fail ("Image file not found for comparison test in: "
365
- "\n \t {baseline_dir}"
366
- "\n (This is expected for new tests.)\n Generated Image: "
367
- "\n \t {test}" .format (baseline_dir = self .get_baseline_directory (item ),
368
- test = test_image ),
369
- pytrace = False )
364
+ return ("Image file not found for comparison test in: \n \t "
365
+ f"{ self .get_baseline_directory (item )} \n "
366
+ "(This is expected for new tests.)\n "
367
+ "Generated Image: \n \t "
368
+ f"{ test_image } " )
370
369
371
370
# distutils may put the baseline images in non-accessible places,
372
371
# copy to our tmpdir to be sure to keep them in case of failure
@@ -379,11 +378,10 @@ def compare_image_to_baseline(self, item, fig, result_dir):
379
378
expected_shape = imread (str (baseline_image )).shape [:2 ]
380
379
actual_shape = imread (str (test_image )).shape [:2 ]
381
380
if expected_shape != actual_shape :
382
- error = SHAPE_MISMATCH_ERROR .format (expected_path = baseline_image ,
383
- expected_shape = expected_shape ,
384
- actual_path = test_image ,
385
- actual_shape = actual_shape )
386
- pytest .fail (error , pytrace = False )
381
+ return SHAPE_MISMATCH_ERROR .format (expected_path = baseline_image ,
382
+ expected_shape = expected_shape ,
383
+ actual_path = test_image ,
384
+ actual_shape = actual_shape )
387
385
388
386
return compare_images (str (baseline_image ), str (test_image ), tol = tolerance )
389
387
@@ -408,10 +406,28 @@ def compare_image_to_hash_library(self, item, fig, result_dir):
408
406
409
407
test_hash = self .generate_image_hash (item , fig )
410
408
411
- if test_hash != hash_library [hash_name ]:
412
- return (f"hash { test_hash } doesn't match hash "
413
- f"{ hash_library [hash_name ]} in library "
414
- f"{ hash_library_filename } for test { hash_name } ." )
409
+ if test_hash == hash_library [hash_name ]:
410
+ return
411
+
412
+ try :
413
+ baseline_image = self .obtain_baseline_image (item , result_dir )
414
+ baseline_image = None if not baseline_image .exists () else baseline_image
415
+ except Exception :
416
+ baseline_image = None
417
+
418
+ hash_error = (f"hash { test_hash } doesn't match hash "
419
+ f"{ hash_library [hash_name ]} in library "
420
+ f"{ hash_library_filename } for test { hash_name } ." )
421
+
422
+ if baseline_image is None :
423
+ return hash_error
424
+
425
+ comparison_error = self .compare_image_to_baseline (item , fig , result_dir )
426
+
427
+ if not comparison_error :
428
+ return hash_error + "\n However, the comparison to the baseline image succeeded."
429
+
430
+ return f"{ hash_error } \n { comparison_error } "
415
431
416
432
def pytest_runtest_setup (self , item ): # noqa
417
433
0 commit comments