Skip to content

Commit

Permalink
Handle tests which do not complete
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ConorMacBride committed Jun 29, 2022
1 parent 32b9a12 commit d84892b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pytest_mpl/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ def pytest_runtest_call(self, item): # noqa
wrap_figure_interceptor(self, item)
yield
test_name = generate_test_name(item)
if test_name not in self.return_value:
# Test function did not complete successfully
return
fig = self.return_value[test_name]

if remove_text:
Expand Down Expand Up @@ -749,5 +752,8 @@ def pytest_runtest_call(self, item):
yield
if get_compare(item) is not None:
test_name = generate_test_name(item)
if test_name not in self.return_value:
# Test function did not complete successfully
return
fig = self.return_value[test_name]
close_mpl_figure(fig)

0 comments on commit d84892b

Please sign in to comment.