0.16.0 breaks with `AttributeError: ImageComparison object has no attribute result`
michaelbrundage opened this issue · 2 comments
michaelbrundage commented
pytest-mpl 0.15.0
was working for us, but pytest-mpl 0.16.0
has broken our tests with an error inside pytest-mpl
.
On Python 3.9 running on my laptop, an example stack trace is:
_________________________________________________________ TimeSeriesDataOpsTest.test_plot _________________________________________________________
self = <pytest_mpl.plugin.ImageComparison object at 0x139932340>, item = <TestCaseFunction test_plot>
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(self, item): # noqa
compare = get_compare(item)
if compare is None:
yield
return
import matplotlib.pyplot as plt
try:
from matplotlib.testing.decorators import remove_ticks_and_titles
except ImportError:
from matplotlib.testing.decorators import ImageComparisonTest as MplImageComparisonTest
remove_ticks_and_titles = MplImageComparisonTest.remove_text
style = compare.kwargs.get('style', 'classic')
remove_text = compare.kwargs.get('remove_text', False)
backend = compare.kwargs.get('backend', 'agg')
with plt.style.context(style, after_reset=True), switch_backend(backend):
# Run test and get figure object
yield
> fig = self.result
E AttributeError: 'ImageComparison' object has no attribute 'result'
/usr/local/lib/python3.9/site-packages/pytest_mpl/plugin.py:611: AttributeError
-------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------
On Python 3.7 running on GitHub, this points to FigureCloser
instead, but otherwise the same error:
self = <pytest_mpl.plugin.FigureCloser object at 0x7fa83e0c2dd0>
item = <TestCaseFunction test_plot>
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(self, item):
yield
if get_compare(item) is not None:
> close_mpl_figure(self.result)
E AttributeError: 'FigureCloser' object has no attribute 'result'
/opt/hostedtoolcache/Python/3.7.13/x64/lib/python3.7/site-packages/pytest_mpl/plugin.py:740: AttributeError
ConorMacBride commented
Thanks for the bug report @michaelbrundage! 👍 The latest pytest-mpl release made some changes to how it integrates with pytest, however, it turns out the way it integrates is ignored when unittest.TestCase
is used. #171 should fix this issue. I've tested the PR branch on Kats and no errors are raised. We'll hopefully get a bugfix release out soon!
michaelbrundage commented
Great, thanks @ConorMacBride!