From 569505aa68266dec9534d9855c91a445e8144a97 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 10 May 2024 14:18:56 -0400 Subject: [PATCH] TST: Followup corrections to #28205 Make the changes suggested by @ianthomas23, and also mark the ipython tests as using their backend. While the backend is already checked for availability at the top of the respective files, that only checks whether it can be imported, not whether it can be set as the Matplotlib backend. Adding the marker causes our pytest configuration to actually check and skip the test if unavailable (e.g., on Linux without `(WAYLAND_)DISPLAY` set fails to set an interactive backend). --- lib/matplotlib/testing/__init__.py | 2 +- lib/matplotlib/tests/test_backend_inline.py | 2 ++ lib/matplotlib/tests/test_backend_macosx.py | 1 + lib/matplotlib/tests/test_backend_qt.py | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/testing/__init__.py b/lib/matplotlib/testing/__init__.py index c3af36230d4b..8e60267ed608 100644 --- a/lib/matplotlib/testing/__init__.py +++ b/lib/matplotlib/testing/__init__.py @@ -210,4 +210,4 @@ def ipython_in_subprocess(requested_backend_or_gui_framework, all_expected_backe capture_output=True, ) - assert proc.stdout.strip() == f"Out[1]: '{expected_backend}'" + assert proc.stdout.strip().endswith(f"'{expected_backend}'") diff --git a/lib/matplotlib/tests/test_backend_inline.py b/lib/matplotlib/tests/test_backend_inline.py index 6f0d67d51756..4112eb213e2c 100644 --- a/lib/matplotlib/tests/test_backend_inline.py +++ b/lib/matplotlib/tests/test_backend_inline.py @@ -1,6 +1,7 @@ import os from pathlib import Path from tempfile import TemporaryDirectory +import sys import pytest @@ -12,6 +13,7 @@ pytest.importorskip('matplotlib_inline') +@pytest.mark.skipif(sys.version_info[:2] <= (3, 9), reason="Requires Python 3.10+") def test_ipynb(): nb_path = Path(__file__).parent / 'test_inline_01.ipynb' diff --git a/lib/matplotlib/tests/test_backend_macosx.py b/lib/matplotlib/tests/test_backend_macosx.py index 3041bda9f423..7431481de8ae 100644 --- a/lib/matplotlib/tests/test_backend_macosx.py +++ b/lib/matplotlib/tests/test_backend_macosx.py @@ -46,6 +46,7 @@ def new_choose_save_file(title, directory, filename): assert mpl.rcParams["savefig.directory"] == f"{tmp_path}/test" +@pytest.mark.backend('macosx') def test_ipython(): from matplotlib.testing import ipython_in_subprocess ipython_in_subprocess("osx", {(8, 24): "macosx", (7, 0): "MacOSX"}) diff --git a/lib/matplotlib/tests/test_backend_qt.py b/lib/matplotlib/tests/test_backend_qt.py index 7c9e24d066fd..2ccfa73c85ca 100644 --- a/lib/matplotlib/tests/test_backend_qt.py +++ b/lib/matplotlib/tests/test_backend_qt.py @@ -376,6 +376,7 @@ def custom_handler(signum, frame): signal.signal(signal.SIGINT, original_handler) +@pytest.mark.backend('QtAgg', skip_on_importerror=True) def test_ipython(): from matplotlib.testing import ipython_in_subprocess ipython_in_subprocess("qt", {(8, 24): "qtagg", (8, 15): "QtAgg", (7, 0): "Qt5Agg"})