Skip to content

check_figures_equal does not account for changed background colors in comparison #16275

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
andrewzwicky opened this issue Jan 20, 2020 · 2 comments
Labels
status: inactive Marked by the “Stale” Github Action topic: testing

Comments

@andrewzwicky
Copy link

Bug report

Bug summary

When check_figures_equal is used as a decorator, the default behavior is to remove any background color during savefig, so plots which should have a different background color can't be properly compared.

For example, code that should produce a figure with a black background and the reference figure would both be saved as a white background.

Code for reproduction

from matplotlib.testing.decorators import check_figures_equal

def create_test_figure_black_background(fig):
    axis = axis = fig.subplots()
    fig.set_facecolor('black')
    axis.bar(
        [0, 1, 2, 3, 4],
        [4, 5, 7, 9, 2],
        color=["red", "blue", "black", "yellow", "white"],
        edgecolor="black",
    )


@check_figures_equal(extensions=["png"])
def test_dark_background(test_figure, reference_figure):

    ref_ax = reference_figure.subplots()
    ref_ax.bar(
        [0, 1, 2, 3, 4],
        [4, 5, 7, 9, 2],
        color=["red", "blue", "black", "yellow", "white"],
        edgecolor="black",
    )

    create_test_figure_black_background(test_figure)

Actual outcome

running with pytest shows a passing test, even though the test_fig should have a black background and the reference figure has a white background. These are both changed to white in savefig

C:\Users\Andrew\Workspace\TripleAgent> pytest .\triple_agent\ -k test_dark_background
================================================================ test session starts =================================================================
platform win32 -- Python 3.7.5, pytest-4.5.0, py-1.8.0, pluggy-0.9.0
plugins: xdist-1.29.0, forked-1.0.2, cov-2.7.1
collected 1112 items / 1111 deselected / 1 selected

triple_agent\tests\test_plot_types.py .                                                                                                         [100%]

===================================================== 1 passed, 1111 deselected in 2.38 seconds ======================================================

Expected outcome

Expect that backgrounds are preserved so that functionality for backgrounds can be tested.

#15111 would likely solve the issue.

Matplotlib version

  • Operating system: Win10
  • Matplotlib version: 3.1.0
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg (i think?)
  • Python version: 3.7.5
  • Jupyter version (if applicable):
  • Other libraries:
@github-actions
Copy link

github-actions bot commented Jul 7, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jul 7, 2023
@ksunden
Copy link
Member

ksunden commented Jul 7, 2023

Closing as completed because this now correctly flags the test as failed. (Probably due to #15111, as indicated in the original post)

@ksunden ksunden closed this as completed Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: inactive Marked by the “Stale” Github Action topic: testing
Projects
None yet
Development

No branches or pull requests

3 participants