-
Notifications
You must be signed in to change notification settings - Fork 366
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
Matplotlib 3.8 test warning #2277
Conversation
This is probably a naive question, but: why do we switch backends individually for each test, rather than setting to agg once globally? |
That is a good question. I just wanted to quiet the warning (which is repeated for every mpl test), but looking at the backend setting and switching now in the tests I do wonder whether what is really necessary. Especially, |
I think the backend switch every time is there to guard against a test that may choose to use a different backend so then you don't get that leaking out into subsequent tests. That |
@@ -15,6 +15,7 @@ def mpl_test_cleanup(request): | |||
with ExitStack() as stack: | |||
# At exit, close all open figures and switch backend back to original. | |||
stack.callback(plt.switch_backend, plt.get_backend()) | |||
stack.callback(plt.close, 'all') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter whether we close all before or after the switch backend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if line 17 and 18 are swapped the warning is still given. Since the stack goes in reverse order, I think the flow is that on exit the plot is closed, then backend is switched to original.
Rationale
tests\mpl\conftest.py gives the following warning: "MatplotlibDeprecationWarning: Auto-close()ing of figures upon backend switching is deprecated since 3.8 and will be removed two minor releases later. To suppress this warning, explicitly call plt.close('all') first."
Implications
The warning is addressed.