From 182bc0b704da3bdc9cb322f8f70527e9c2aba826 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 8 May 2024 21:19:29 -0400 Subject: [PATCH] TST: Prepare for pytest 9 The current version of pytest is warning that using `importorskip` to catch `ImportError` will start being ignored (and thus raising) with pytest 9. Fortunately, in all cases, we don't need these calls, as they are: - already checked for `ImportError` at the top-level of the file - already checked by the backend switcher - not actually possible to fail importing --- lib/matplotlib/tests/test_backend_bases.py | 6 +++--- lib/matplotlib/tests/test_backend_gtk3.py | 3 --- lib/matplotlib/tests/test_backend_qt.py | 4 +--- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_bases.py b/lib/matplotlib/tests/test_backend_bases.py index c264f01acdb2..3a49f0ec08ec 100644 --- a/lib/matplotlib/tests/test_backend_bases.py +++ b/lib/matplotlib/tests/test_backend_bases.py @@ -1,3 +1,5 @@ +import importlib + from matplotlib import path, transforms from matplotlib.backend_bases import ( FigureCanvasBase, KeyEvent, LocationEvent, MouseButton, MouseEvent, @@ -325,9 +327,7 @@ def test_toolbar_home_restores_autoscale(): def test_draw(backend): from matplotlib.figure import Figure from matplotlib.backends.backend_agg import FigureCanvas - test_backend = pytest.importorskip( - f'matplotlib.backends.backend_{backend}' - ) + test_backend = importlib.import_module(f'matplotlib.backends.backend_{backend}') TestCanvas = test_backend.FigureCanvas fig_test = Figure(constrained_layout=True) TestCanvas(fig_test) diff --git a/lib/matplotlib/tests/test_backend_gtk3.py b/lib/matplotlib/tests/test_backend_gtk3.py index 6a95f47e1ddd..d7fa4329cfc8 100644 --- a/lib/matplotlib/tests/test_backend_gtk3.py +++ b/lib/matplotlib/tests/test_backend_gtk3.py @@ -3,9 +3,6 @@ import pytest -pytest.importorskip("matplotlib.backends.backend_gtk3agg") - - @pytest.mark.backend("gtk3agg", skip_on_importerror=True) def test_correct_key(): pytest.xfail("test_widget_send_event is not triggering key_press_event") diff --git a/lib/matplotlib/tests/test_backend_qt.py b/lib/matplotlib/tests/test_backend_qt.py index 026a49b1441e..a105b88c7449 100644 --- a/lib/matplotlib/tests/test_backend_qt.py +++ b/lib/matplotlib/tests/test_backend_qt.py @@ -26,9 +26,7 @@ @pytest.fixture def qt_core(request): - qt_compat = pytest.importorskip('matplotlib.backends.qt_compat') - QtCore = qt_compat.QtCore - + from matplotlib.backends.qt_compat import QtCore return QtCore