From 44e603eaa6e101483ab68f5c3b6ea7e032a8e376 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 7 Apr 2022 20:07:48 -0400 Subject: [PATCH] TST: fully parameterize test_lazy_linux_headless --- .../tests/test_backends_interactive.py | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/tests/test_backends_interactive.py b/lib/matplotlib/tests/test_backends_interactive.py index 81b9377c750e..c59c5e37bb58 100644 --- a/lib/matplotlib/tests/test_backends_interactive.py +++ b/lib/matplotlib/tests/test_backends_interactive.py @@ -59,7 +59,12 @@ def _get_testable_interactive_backends(): elif env["MPLBACKEND"].startswith('wx') and sys.platform == 'darwin': # ignore on OSX because that's currently broken (github #16849) marks.append(pytest.mark.xfail(reason='github #16849')) - envs.append(pytest.param(env, marks=marks, id=str(env))) + envs.append( + pytest.param( + {**env, 'BACKEND_DEPS': ','.join(deps)}, + marks=marks, id=str(env) + ) + ) return envs @@ -394,22 +399,29 @@ def _lazy_headless(): import os import sys + backend, deps = sys.argv[1:] + deps = deps.split(',') + # make it look headless os.environ.pop('DISPLAY', None) os.environ.pop('WAYLAND_DISPLAY', None) + for dep in deps: + assert dep not in sys.modules # we should fast-track to Agg import matplotlib.pyplot as plt - plt.get_backend() == 'agg' - assert 'PyQt5' not in sys.modules + assert plt.get_backend() == 'agg' + for dep in deps: + assert dep not in sys.modules - # make sure we really have pyqt installed - import PyQt5 # noqa - assert 'PyQt5' in sys.modules + # make sure we really have dependencies installed + for dep in deps: + importlib.import_module(dep) + assert dep in sys.modules # try to switch and make sure we fail with ImportError try: - plt.switch_backend('qt5agg') + plt.switch_backend(backend) except ImportError: ... else: @@ -417,9 +429,14 @@ def _lazy_headless(): @pytest.mark.skipif(sys.platform != "linux", reason="this a linux-only test") -@pytest.mark.backend('Qt5Agg', skip_on_importerror=True) -def test_lazy_linux_headless(): - proc = _run_helper(_lazy_headless, timeout=_test_timeout, MPLBACKEND="") +@pytest.mark.parametrize("env", _get_testable_interactive_backends()) +def test_lazy_linux_headless(env): + proc = _run_helper( + _lazy_headless, + env.pop('MPLBACKEND'), env.pop("BACKEND_DEPS"), + timeout=_test_timeout, + **{**env, 'DISPLAY': '', 'WAYLAND_DISPLAY': ''} + ) def _qApp_warn_impl():