Skip to content

Commit 435a860

Browse files
committed
Ignore MatplotlibDeprecationWarnings when setting up test rcParams.
Otherwise, rcParams cannot be deprecated without spamming stderr with one warning per test.
1 parent f564af7 commit 435a860

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/matplotlib/testing/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import matplotlib as mpl
55
from matplotlib import cbook
6+
from matplotlib.cbook import MatplotlibDeprecationWarning
67

78

89
def is_called_from_pytest():
@@ -38,10 +39,11 @@ def setup():
3839

3940
mpl.use('Agg', warn=False) # use Agg backend for these tests
4041

41-
# These settings *must* be hardcoded for running the comparison
42-
# tests and are not necessarily the default values as specified in
43-
# rcsetup.py
44-
mpl.rcdefaults() # Start with all defaults
42+
# These settings *must* be hardcoded for running the comparison tests and
43+
# are not necessarily the default values as specified in rcsetup.py
44+
with warnings.catch_warnings():
45+
warnings.simplefilter("ignore", MatplotlibDeprecationWarning)
46+
mpl.rcdefaults() # Start with all defaults
4547

4648
set_font_settings_for_testing()
4749
set_reproducibility_for_testing()

lib/matplotlib/testing/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import warnings
2+
13
import pytest
24

35
import matplotlib
46
from matplotlib import cbook
7+
from matplotlib.cbook import MatplotlibDeprecationWarning
58

69

710
def pytest_configure(config):
@@ -41,7 +44,9 @@ def mpl_test_settings(request):
4144
# default backend prematurely.
4245
import matplotlib.pyplot as plt
4346
plt.switch_backend(backend)
44-
matplotlib.style.use(style)
47+
with warnings.catch_warnings():
48+
warnings.simplefilter("ignore", MatplotlibDeprecationWarning)
49+
matplotlib.style.use(style)
4550
try:
4651
yield
4752
finally:

0 commit comments

Comments
 (0)