Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.16.0 breaks with AttributeError: ImageComparison object has no attribute result #170

Closed
michaelbrundage opened this issue Jun 24, 2022 · 2 comments · Fixed by #171
Closed
Labels

Comments

@michaelbrundage
Copy link

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

Failed Github Action

facebook-github-bot pushed a commit to facebookresearch/Kats that referenced this issue Jun 24, 2022
Summary:
External dependency `pytest-mpl` updated to 0.16.0 and broke some of our visual tests. 0.15.0 still works, so constrain its version in `test_requirements.txt`.

Upstream issue: matplotlib/pytest-mpl#170

Reviewed By: rohanfb

Differential Revision: D37432632

fbshipit-source-id: 3215444d927f4d9cea2fa97228a1776307d663eb
@ConorMacBride
Copy link
Member

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
Copy link
Author

Great, thanks @ConorMacBride!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants