Skip to content

Commit d84892b

Browse files
committed
Handle tests which do not complete
If the return value hasn't been added to the dictionary, it means that the user's test didn't reach the end. This means that it raised an exception or was otherwise stopped early by pytest (skipped, failed, etc). In any case, we should not proceed with figure testing and use the result that pytest has already determined. Fixes #172
1 parent 32b9a12 commit d84892b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pytest_mpl/plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,9 @@ def pytest_runtest_call(self, item): # noqa
622622
wrap_figure_interceptor(self, item)
623623
yield
624624
test_name = generate_test_name(item)
625+
if test_name not in self.return_value:
626+
# Test function did not complete successfully
627+
return
625628
fig = self.return_value[test_name]
626629

627630
if remove_text:
@@ -749,5 +752,8 @@ def pytest_runtest_call(self, item):
749752
yield
750753
if get_compare(item) is not None:
751754
test_name = generate_test_name(item)
755+
if test_name not in self.return_value:
756+
# Test function did not complete successfully
757+
return
752758
fig = self.return_value[test_name]
753759
close_mpl_figure(fig)

0 commit comments

Comments
 (0)