Skip to content

Commit 187c057

Browse files
committed
Merge pull request #27624 from ksunden/pytest8
Prepare for Pytest v8 (cherry picked from commit ed41aea)
1 parent b8297e4 commit 187c057

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

lib/matplotlib/tests/test_colors.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
import itertools
33
import unittest.mock
4+
from packaging.version import parse as parse_version
45

56
from io import BytesIO
67
import numpy as np
@@ -146,9 +147,13 @@ def test_double_register_builtin_cmap():
146147
with pytest.raises(ValueError, match='A colormap named "viridis"'):
147148
with pytest.warns(mpl.MatplotlibDeprecationWarning):
148149
cm.register_cmap(name, mpl.colormaps[name])
149-
with pytest.warns(UserWarning):
150-
# TODO is warning more than once!
151-
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)
150+
151+
if parse_version(pytest.__version__).major < 8:
152+
with pytest.warns(UserWarning):
153+
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)
154+
else:
155+
with pytest.warns(UserWarning), pytest.warns(mpl.MatplotlibDeprecationWarning):
156+
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)
152157

153158

154159
def test_unregister_builtin_cmap():

lib/matplotlib/tests/test_rcparams.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,12 @@ def test_rcparams_update():
107107
rc = mpl.RcParams({'figure.figsize': (3.5, 42)})
108108
bad_dict = {'figure.figsize': (3.5, 42, 1)}
109109
# make sure validation happens on input
110-
with pytest.raises(ValueError), \
111-
pytest.warns(UserWarning, match="validate"):
110+
with pytest.raises(ValueError):
112111
rc.update(bad_dict)
113112

114113

115114
def test_rcparams_init():
116-
with pytest.raises(ValueError), \
117-
pytest.warns(UserWarning, match="validate"):
115+
with pytest.raises(ValueError):
118116
mpl.RcParams({'figure.figsize': (3.5, 42, 1)})
119117

120118

lib/matplotlib/tests/test_ticker.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import locale
44
import logging
55
import re
6+
from packaging.version import parse as parse_version
67

78
import numpy as np
89
from numpy.testing import assert_almost_equal, assert_array_equal
@@ -730,10 +731,17 @@ def test_mathtext_ticks(self):
730731
'axes.formatter.use_mathtext': False
731732
})
732733

733-
with pytest.warns(UserWarning, match='cmr10 font should ideally'):
734-
fig, ax = plt.subplots()
735-
ax.set_xticks([-1, 0, 1])
736-
fig.canvas.draw()
734+
if parse_version(pytest.__version__).major < 8:
735+
with pytest.warns(UserWarning, match='cmr10 font should ideally'):
736+
fig, ax = plt.subplots()
737+
ax.set_xticks([-1, 0, 1])
738+
fig.canvas.draw()
739+
else:
740+
with (pytest.warns(UserWarning, match="Glyph 8722"),
741+
pytest.warns(UserWarning, match='cmr10 font should ideally')):
742+
fig, ax = plt.subplots()
743+
ax.set_xticks([-1, 0, 1])
744+
fig.canvas.draw()
737745

738746
def test_cmr10_substitutions(self, caplog):
739747
mpl.rcParams.update({

0 commit comments

Comments
 (0)