You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
check_figures_equal decorator reuses figures if called multiple times inside a single test. #15079
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.
Probably one should just wrap the whole thing in a try... finally: plt.close(fig_test); plt.close(fitg_ref)? In our own test suite this is done by an autouse fixture but I guess adding the close() to check_figures_equal makes it more usable by third-party packages.
All our tests autouse a fixture from matplotlib.testing.conftest that closes all figure at the end of a test. If you're not running these as Matplotlib tests, you'll need to replicate that behaviour.
Both of those make sense. Is check_figures_equal intended for use in third-party projects? It seems quite useful, so it might make sense to either update the documentation re: extra testing steps for closing figures or include that functionality to close just those two figures. Do maintainers have a preference? It seems like a relatively small thing I can contribute.
I just tested a small fix with try/finally and it worked as I expected. I think having to add extra figure closing stuff in my own test suite would make me scratch my head a bit, so I'd prefer the plt.close included in the wrapper, but I understand if that's not desirable for some other reason.
Activity
anntzer commentedon Aug 18, 2019
Probably one should just wrap the whole thing in a
try... finally: plt.close(fig_test); plt.close(fitg_ref)? In our own test suite this is done by an autouse fixture but I guess adding the close() to check_figures_equal makes it more usable by third-party packages.QuLogic commentedon Aug 18, 2019
All our tests autouse a fixture from
matplotlib.testing.conftestthat closes all figure at the end of a test. If you're not running these as Matplotlib tests, you'll need to replicate that behaviour.andrewzwicky commentedon Aug 18, 2019
Both of those make sense. Is
check_figures_equalintended for use in third-party projects? It seems quite useful, so it might make sense to either update the documentation re: extra testing steps for closing figures or include that functionality to close just those two figures. Do maintainers have a preference? It seems like a relatively small thing I can contribute.I just tested a small fix with
try/finallyand it worked as I expected. I think having to add extra figure closing stuff in my own test suite would make me scratch my head a bit, so I'd prefer theplt.closeincluded in the wrapper, but I understand if that's not desirable for some other reason.anntzer commentedon Aug 18, 2019
I'm personally fine with a pr adding the call to close.