Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fd9a42

Browse files
committed
Prepare for Pytest v8
The behavior of pytest.warns has changed, particularly with regards to handling of additional warnings
1 parent b0f015c commit 9fd9a42

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io
44
import os
55
from pathlib import Path
6+
import warnings
67

78
import numpy as np
89
import pytest
@@ -84,6 +85,9 @@ def test_multipage_keep_empty(tmp_path):
8485
os.chdir(tmp_path)
8586

8687
# test empty pdf files
88+
# Due to order of `with` block execution, a warning for unclosed file is raised
89+
# but the pytest.warns must happen before the PdfPages is created
90+
warnings.filterwarnings("ignore", category=ResourceWarning)
8791

8892
# an empty pdf is left behind with keep_empty unset
8993
with pytest.warns(mpl.MatplotlibDeprecationWarning), PdfPages("a.pdf") as pdf:

lib/matplotlib/tests/test_colors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ def test_double_register_builtin_cmap():
147147
with pytest.raises(ValueError, match='A colormap named "viridis"'):
148148
with pytest.warns(mpl.MatplotlibDeprecationWarning):
149149
cm.register_cmap(name, mpl.colormaps[name])
150-
with pytest.warns(UserWarning):
151-
# TODO is warning more than once!
150+
with pytest.warns(UserWarning), pytest.warns(mpl.MatplotlibDeprecationWarning):
152151
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)
153152

154153

lib/matplotlib/tests/test_rcparams.py

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

113112

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

119117

lib/matplotlib/tests/test_ticker.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import locale
44
import logging
55
import re
6+
import warnings
67

78
import numpy as np
89
from numpy.testing import assert_almost_equal, assert_array_equal
@@ -914,6 +915,9 @@ def test_mathtext_ticks(self):
914915
'axes.formatter.use_mathtext': False
915916
})
916917

918+
# Glyph warning unrelated
919+
warnings.filterwarnings("ignore", category=UserWarning, message="Glyph 8722")
920+
917921
with pytest.warns(UserWarning, match='cmr10 font should ideally'):
918922
fig, ax = plt.subplots()
919923
ax.set_xticks([-1, 0, 1])

0 commit comments

Comments
 (0)