@@ -293,6 +293,7 @@ def __init__(self,
293
293
294
294
# We need global state to store all the hashes generated over the run
295
295
self ._generated_hash_library = {}
296
+ self ._test_results = {}
296
297
297
298
def get_compare (self , item ):
298
299
"""
@@ -504,28 +505,27 @@ def compare_image_to_hash_library(self, item, fig, result_dir):
504
505
if not hash_comparison_pass and not self .baseline_directory_specified (item ) or new_test :
505
506
return error_message
506
507
507
- # Get the baseline and generate a diff image, always so that
508
- # --mpl-results-always can be respected.
509
- # Ignore Errors here as it's possible the reference image dosen't exist yet.
510
- try :
511
- baseline_comparison = self .compare_image_to_baseline (item , fig , result_dir )
512
- except Exception as e :
513
- pass
514
-
515
- # If the hash comparison passes then return
516
- if hash_comparison_pass :
517
- return
518
-
519
508
# If this is not a new test try and get the baseline image.
520
509
if not new_test :
521
- baseline_image_path = self .obtain_baseline_image (item , result_dir )
510
+ # Ignore Errors here as it's possible the reference image dosen't exist yet.
511
+ try :
512
+ baseline_image_path = self .obtain_baseline_image (item , result_dir )
513
+ # Get the baseline and generate a diff image, always so that
514
+ # --mpl-results-always can be respected.
515
+ baseline_comparison = self .compare_image_to_baseline (item , fig , result_dir )
516
+ except Exception as e :
517
+ warnings .warn (str (e ))
522
518
523
519
try :
524
520
baseline_image = baseline_image_path
525
521
baseline_image = None if (baseline_image and not baseline_image .exists ()) else baseline_image
526
522
except Exception :
527
523
baseline_image = None
528
524
525
+ # If the hash comparison passes then return
526
+ if hash_comparison_pass :
527
+ return
528
+
529
529
if baseline_image is None :
530
530
error_message += f"\n Unable to find baseline image { baseline_image_path or '' } ."
531
531
return error_message
@@ -579,6 +579,8 @@ def item_function_wrapper(*args, **kwargs):
579
579
if remove_text :
580
580
remove_ticks_and_titles (fig )
581
581
582
+ test_name = self .generate_test_name (item )
583
+
582
584
# What we do now depends on whether we are generating the
583
585
# reference images or simply running the test.
584
586
if self .generate_dir is not None :
@@ -587,8 +589,7 @@ def item_function_wrapper(*args, **kwargs):
587
589
pytest .skip ("Skipping test, since generating image." )
588
590
589
591
if self .generate_hash_library is not None :
590
- hash_name = self .generate_test_name (item )
591
- self ._generated_hash_library [hash_name ] = self .generate_image_hash (item , fig )
592
+ self ._generated_hash_library [test_name ] = self .generate_image_hash (item , fig )
592
593
pytest .skip ("Skipping test as generating hash library." )
593
594
594
595
# Only test figures if we are not generating hashes or images
@@ -605,6 +606,8 @@ def item_function_wrapper(*args, **kwargs):
605
606
606
607
close_mpl_figure (fig )
607
608
609
+ self ._test_results [str (pathify (test_name ))] = msg or True
610
+
608
611
if msg is None :
609
612
if not self .results_always :
610
613
shutil .rmtree (result_dir )
@@ -627,8 +630,14 @@ def generate_summary_html(self, dir_list):
627
630
f .write (HTML_INTRO )
628
631
629
632
for directory in dir_list :
633
+ test_name = directory .parts [- 1 ]
634
+ if test_name not in self ._test_results :
635
+ breakpoint ()
636
+ test_result = 'no baseline image'
637
+ else :
638
+ test_result = 'passed' if self ._test_results [test_name ] is True else 'failed'
630
639
f .write ('<tr>'
631
- f'<td>{ directory . parts [ - 1 ] } \n '
640
+ f'<td>{ test_name } ( { test_result } ) \n '
632
641
f'<td><img src="{ directory / "baseline.png" } "></td>\n '
633
642
f'<td><img src="{ directory / "result-failed-diff.png" } "></td>\n '
634
643
f'<td><img src="{ directory / "result.png" } "></td>\n '
0 commit comments