Skip to content

Commit 61d4eed

Browse files
committed
Report if test function raised an exception
1 parent d0b534e commit 61d4eed

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

pytest_mpl/plugin.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ def compare_image_to_hash_library(self, item, fig, result_dir, summary=None):
597597
baseline_comparison = self.compare_image_to_baseline(item, fig, result_dir,
598598
summary=baseline_summary)
599599
except Exception as baseline_error: # Append to test error later
600+
summary['image_status'] = 'diff' # (not necessarily diff, but makes user aware)
600601
baseline_comparison = str(baseline_error)
601602
else: # Update main summary
602603
for k in ['image_status', 'baseline_image', 'diff_image',
@@ -635,25 +636,14 @@ def pytest_runtest_call(self, item): # noqa
635636

636637
with plt.style.context(style, after_reset=True), switch_backend(backend):
637638

638-
# Run test and get figure object
639-
wrap_figure_interceptor(self, item)
640-
yield
641639
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)
651640

641+
# Store fallback summary in case of exceptions
652642
summary = {
653-
'status': None,
643+
'status': 'failed',
654644
'image_status': None,
655645
'hash_status': None,
656-
'status_msg': None,
646+
'status_msg': 'An exception was raised while testing the figure.',
657647
'baseline_image': None,
658648
'diff_image': None,
659649
'rms': None,
@@ -662,6 +652,24 @@ def pytest_runtest_call(self, item): # noqa
662652
'baseline_hash': None,
663653
'result_hash': None,
664654
}
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)
665673

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

0 commit comments

Comments
 (0)