@@ -657,6 +657,7 @@ def compare_image_to_hash_library(self, item, fig, result_dir, summary=None):
657
657
baseline_comparison = self .compare_image_to_baseline (item , fig , result_dir ,
658
658
summary = baseline_summary )
659
659
except Exception as baseline_error : # Append to test error later
660
+ summary ['image_status' ] = 'diff' # (not necessarily diff, but makes user aware)
660
661
baseline_comparison = str (baseline_error )
661
662
else : # Update main summary
662
663
for k in ['image_status' , 'baseline_image' , 'diff_image' ,
@@ -697,25 +698,14 @@ def pytest_runtest_call(self, item): # noqa
697
698
698
699
with plt .style .context (style , after_reset = True ), switch_backend (backend ):
699
700
700
- # Run test and get figure object
701
- wrap_figure_interceptor (self , item )
702
- yield
703
701
test_name = generate_test_name (item )
704
- if test_name not in self .return_value :
705
- # Test function did not complete successfully
706
- return
707
- fig = self .return_value [test_name ]
708
-
709
- if remove_text :
710
- remove_ticks_and_titles (fig )
711
-
712
- result_dir = self .make_test_results_dir (item )
713
702
703
+ # Store fallback summary in case of exceptions
714
704
summary = {
715
- 'status' : None ,
705
+ 'status' : 'failed' ,
716
706
'image_status' : None ,
717
707
'hash_status' : None ,
718
- 'status_msg' : None ,
708
+ 'status_msg' : 'An exception was raised while testing the figure.' ,
719
709
'baseline_image' : None ,
720
710
'diff_image' : None ,
721
711
'rms' : None ,
@@ -724,6 +714,24 @@ def pytest_runtest_call(self, item): # noqa
724
714
'baseline_hash' : None ,
725
715
'result_hash' : None ,
726
716
}
717
+ self ._test_results [test_name ] = summary
718
+
719
+ # Run test and get figure object
720
+ wrap_figure_interceptor (self , item )
721
+ yield
722
+ if test_name not in self .return_value :
723
+ # Test function did not complete successfully
724
+ summary ['status' ] = 'failed'
725
+ summary ['status_msg' ] = ('Test function raised an exception '
726
+ 'before returning a figure.' )
727
+ self ._test_results [test_name ] = summary
728
+ return
729
+ fig = self .return_value [test_name ]
730
+
731
+ if remove_text :
732
+ remove_ticks_and_titles (fig )
733
+
734
+ result_dir = self .make_test_results_dir (item )
727
735
728
736
# What we do now depends on whether we are generating the
729
737
# reference images or simply running the test.
0 commit comments