8000 check_figures_equal decorator reuses figures if called multiple times inside a single test. · Issue #15079 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
check_figures_equal decorator reuses figures if called multiple times inside a single test. #15079
Closed
@andrewzwicky

Description

@andrewzwicky

Bug report

Bug summary

When running a test suite with multiple tests using check_figures_equal, figures are re-used, causing plot elements to become "stacked", causing tests to unexpectedly fail.

Code for reproduction

from matplotlib.testing.decorators import check_figures_equal
from matplotlib import pyplot as plt

@check_figures_equal(extensions=["png"])
def test_red_line_first(test_figure, reference_figure):
    red_circle = plt.Circle((0, 0), 0.2, color='r', clip_on=False)
    reference_figure.add_artist(red_circle)
    reference_figure.subplots().plot([0,1,2], [3,4,5], color='red')    


@check_figures_equal(extensions=["png"])
def test_blue_line_second(test_figure, reference_figure):
    blue_circle = plt.Circle((1, 1), 0.2, color='b', clip_on=False)
    reference_figure.add_artist(blue_circle)
    reference_figure.subplots().plot([0,1,2], [4,4,4], color='blue')


@check_figures_equal(extensions=["png"])
def test_green_line_third(test_figure, reference_figure):
    green_circle = plt.Circle((1, 0), 0.2, color='g', clip_on=False)
    reference_figure.add_artist(green_circle)
    reference_figure.subplots().plot([0,1,2], [5,4,3], color='green')

running as:
pytest .\mpl_figure_equal_test.py

Actual outcome
Reference Screenshots:
test_red_line_first-expected
test_blue_line_second-expected
test_green_line_third-expected

Expected outcome
Reference Screenshots:
test_red_line_first-expected
test_blue_line_second-expected
test_green_line_third-expected

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: matplotlib 3.1.0
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.7.3
  • Jupyter version (if applicable):
  • Other libraries: pytest 4.5.0

everything installed via pip

fig_test = plt.figure("test")
fig_ref = plt.figure("reference")

I'm guessing these lines are at fault, and might need some kind of other information to distinguish them?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good first issueOpen a pull request against these issues if there are no active ones!topic: testing

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0