Skip to content

[Bug]: check_figures_equal decorator doesn't respect new figure properties set in test #24875

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

Closed
chahak13 opened this issue Jan 3, 2023 · 4 comments

Comments

@chahak13
Copy link
Contributor

chahak13 commented Jan 3, 2023

Bug summary

We use the check_figures_equal in testing to compare figures. This decorator uses two figure instances fig_test and fig_ref for comparison. If we set any figure properties (like facecolor) in the test, they don't seem to be propagated when saving the actual figure.

Ran into this while writing a test for #24816 (cc @anntzer, for reference)

Code for reproduction

@check_figures_equal(extensions=["png"])
def test_test(fig_test, fig_ref):
    ax_test = fig_test.add_subplot()
    ax_test.set(xticks=[], yticks=[])
    fig_test.set_facecolor("teal")

    ax_ref = fig_ref.add_subplot()
    ax_ref.set(xticks=[], yticks=[])
    fig_ref.set_facecolor("none")

Actual outcome

This test passes, which suggests that the two figures created are equal but they actually aren't since the facecolor for both figures are set to be different.

Expected outcome

This test shouldn't pass and the figures should have facecolors "teal" and "none" respectively.

Additional information

No response

Operating system

Arch

Matplotlib Version

3.6.0.dev1889+gc59a7fa8db.d20230103

Matplotlib Backend

No response

Python version

3.10

Jupyter version

No response

Installation

None

@anntzer
Copy link
Contributor

anntzer commented Jan 3, 2023

I haven't actually checked, but are you sure this is not due to a combination of a) tests defaulting to running with the classic (pre-mpl2) style and b) classic style setting savefig.facecolor = savefig.edgecolor = w? (The new default style sets savefig.facecolor = savefig.edgecolor = auto, which means "don't change it".)

@chahak13
Copy link
Contributor Author

chahak13 commented Jan 4, 2023

It is indeed because of the default style being classic. I added an option to change style to the decorator and it worked with "mpl20". Shouldn't check_figures_equal also have an option like image_comparison to set style?

@chahak13
Copy link
Contributor Author

chahak13 commented Jan 4, 2023

Also, how is the default determined? I'm not changing anything for it to run in classic or otherwise.

@anntzer
Copy link
Contributor

anntzer commented Jan 4, 2023

Just decorate with @mpl.style.use(...) outside of the test decorator?
The default is determined by matplotlib.testing.conftest.mpl_test_settings.

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

No branches or pull requests

2 participants