diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index d66e199b25b2..573b401c1950 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -2728,7 +2728,7 @@ def close(self): _api.warn_deprecated("3.8", message=( "Keeping empty pdf files is deprecated since %(since)s and support " "will be removed %(removal)s.")) - PdfFile(self._filename, metadata=self._metadata) # touch the file. + PdfFile(self._filename, metadata=self._metadata).close() # touch the file. def infodict(self): """ diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index 139efbe17407..35030b6bea7a 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -1,6 +1,7 @@ import copy import itertools import unittest.mock +from packaging.version import parse as parse_version from io import BytesIO import numpy as np @@ -147,9 +148,13 @@ def test_double_register_builtin_cmap(): with pytest.raises(ValueError, match='A colormap named "viridis"'): with pytest.warns(mpl.MatplotlibDeprecationWarning): cm.register_cmap(name, mpl.colormaps[name]) - with pytest.warns(UserWarning): - # TODO is warning more than once! - cm.register_cmap(name, mpl.colormaps[name], override_builtin=True) + + if parse_version(pytest.__version__).major < 8: + with pytest.warns(UserWarning): + cm.register_cmap(name, mpl.colormaps[name], override_builtin=True) + else: + with pytest.warns(UserWarning), pytest.warns(mpl.MatplotlibDeprecationWarning): + cm.register_cmap(name, mpl.colormaps[name], override_builtin=True) def test_unregister_builtin_cmap(): diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index e3e10145533d..782c390c9462 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -106,14 +106,12 @@ def test_rcparams_update(): rc = mpl.RcParams({'figure.figsize': (3.5, 42)}) bad_dict = {'figure.figsize': (3.5, 42, 1)} # make sure validation happens on input - with pytest.raises(ValueError), \ - pytest.warns(UserWarning, match="validate"): + with pytest.raises(ValueError): rc.update(bad_dict) def test_rcparams_init(): - with pytest.raises(ValueError), \ - pytest.warns(UserWarning, match="validate"): + with pytest.raises(ValueError): mpl.RcParams({'figure.figsize': (3.5, 42, 1)}) diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 12eafba9ea2b..4b37d5c52206 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -3,6 +3,7 @@ import locale import logging import re +from packaging.version import parse as parse_version import numpy as np from numpy.testing import assert_almost_equal, assert_array_equal @@ -914,10 +915,17 @@ def test_mathtext_ticks(self): 'axes.formatter.use_mathtext': False }) - with pytest.warns(UserWarning, match='cmr10 font should ideally'): - fig, ax = plt.subplots() - ax.set_xticks([-1, 0, 1]) - fig.canvas.draw() + if parse_version(pytest.__version__).major < 8: + with pytest.warns(UserWarning, match='cmr10 font should ideally'): + fig, ax = plt.subplots() + ax.set_xticks([-1, 0, 1]) + fig.canvas.draw() + else: + with (pytest.warns(UserWarning, match="Glyph 8722"), + pytest.warns(UserWarning, match='cmr10 font should ideally')): + fig, ax = plt.subplots() + ax.set_xticks([-1, 0, 1]) + fig.canvas.draw() def test_cmr10_substitutions(self, caplog): mpl.rcParams.update({