Skip to content

Commit 8a0ec45

Browse files
committed
Report if test function raised an exception
1 parent 24ba2aa commit 8a0ec45

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

Diff for: pytest_mpl/plugin.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ def compare_image_to_hash_library(self, item, fig, result_dir, summary=None):
657657
baseline_comparison = self.compare_image_to_baseline(item, fig, result_dir,
658658
summary=baseline_summary)
659659
except Exception as baseline_error: # Append to test error later
660+
summary['image_status'] = 'diff' # (not necessarily diff, but makes user aware)
660661
baseline_comparison = str(baseline_error)
661662
else: # Update main summary
662663
for k in ['image_status', 'baseline_image', 'diff_image',
@@ -697,25 +698,14 @@ def pytest_runtest_call(self, item): # noqa
697698

698699
with plt.style.context(style, after_reset=True), switch_backend(backend):
699700

700-
# Run test and get figure object
701-
wrap_figure_interceptor(self, item)
702-
yield
703701
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)
713702

703+
# Store fallback summary in case of exceptions
714704
summary = {
715-
'status': None,
705+
'status': 'failed',
716706
'image_status': None,
717707
'hash_status': None,
718-
'status_msg': None,
708+
'status_msg': 'An exception was raised while testing the figure.',
719709
'baseline_image': None,
720710
'diff_image': None,
721711
'rms': None,
@@ -724,6 +714,24 @@ def pytest_runtest_call(self, item): # noqa
724714
'baseline_hash': None,
725715
'result_hash': None,
726716
}
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)
727735

728736
# What we do now depends on whether we are generating the
729737
# reference images or simply running the test.

0 commit comments

Comments
 (0)