@@ -597,6 +597,7 @@ def compare_image_to_hash_library(self, item, fig, result_dir, summary=None):
597
597
baseline_comparison = self .compare_image_to_baseline (item , fig , result_dir ,
598
598
summary = baseline_summary )
599
599
except Exception as baseline_error : # Append to test error later
600
+ summary ['image_status' ] = 'diff' # (not necessarily diff, but makes user aware)
600
601
baseline_comparison = str (baseline_error )
601
602
else : # Update main summary
602
603
for k in ['image_status' , 'baseline_image' , 'diff_image' ,
@@ -635,25 +636,14 @@ def pytest_runtest_call(self, item): # noqa
635
636
636
637
with plt .style .context (style , after_reset = True ), switch_backend (backend ):
637
638
638
- # Run test and get figure object
639
- wrap_figure_interceptor (self , item )
640
- yield
641
639
test_name = generate_test_name (item )
642
- if test_name not in self .return_value :
643
- # Test function did not complete successfully
644
- return
645
- fig = self .return_value [test_name ]
646
-
647
- if remove_text :
648
- remove_ticks_and_titles (fig )
649
-
650
- result_dir = self .make_test_results_dir (item )
651
640
641
+ # Store fallback summary in case of exceptions
652
642
summary = {
653
- 'status' : None ,
643
+ 'status' : 'failed' ,
654
644
'image_status' : None ,
655
645
'hash_status' : None ,
656
- 'status_msg' : None ,
646
+ 'status_msg' : 'An exception was raised while testing the figure.' ,
657
647
'baseline_image' : None ,
658
648
'diff_image' : None ,
659
649
'rms' : None ,
@@ -662,6 +652,24 @@ def pytest_runtest_call(self, item): # noqa
662
652
'baseline_hash' : None ,
663
653
'result_hash' : None ,
664
654
}
655
+ self ._test_results [test_name ] = summary
656
+
657
+ # Run test and get figure object
658
+ wrap_figure_interceptor (self , item )
659
+ yield
660
+ if test_name not in self .return_value :
661
+ # Test function did not complete successfully
662
+ summary ['status' ] = 'failed'
663
+ summary ['status_msg' ] = ('Test function raised an exception '
664
+ 'before returning a figure.' )
665
+ self ._test_results [test_name ] = summary
666
+ return
667
+ fig = self .return_value [test_name ]
668
+
669
+ if remove_text :
670
+ remove_ticks_and_titles (fig )
671
+
672
+ result_dir = self .make_test_results_dir (item )
665
673
666
674
# What we do now depends on whether we are generating the
667
675
# reference images or simply running the test.
0 commit comments