Closed
Description
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:
Expected outcome
Reference Screenshots:
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
matplotlib/lib/matplotlib/testing/decorators.py
Lines 394 to 395 in e86c9cd
I'm guessing these lines are at fault, and might need some kind of other information to distinguish them?