Skip to content

Commit 44e603e

Browse files
committed
TST: fully parameterize test_lazy_linux_headless
1 parent 574580c commit 44e603e

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ def _get_testable_interactive_backends():
5959
elif env["MPLBACKEND"].startswith('wx') and sys.platform == 'darwin':
6060
# ignore on OSX because that's currently broken (github #16849)
6161
marks.append(pytest.mark.xfail(reason='github #16849'))
62-
envs.append(pytest.param(env, marks=marks, id=str(env)))
62+
envs.append(
63+
pytest.param(
64+
{**env, 'BACKEND_DEPS': ','.join(deps)},
65+
marks=marks, id=str(env)
66+
)
67+
)
6368
return envs
6469

6570

@@ -394,32 +399,44 @@ def _lazy_headless():
394399
import os
395400
import sys
396401

402+
backend, deps = sys.argv[1:]
403+
deps = deps.split(',')
404+
397405
# make it look headless
398406
os.environ.pop('DISPLAY', None)
399407
os.environ.pop('WAYLAND_DISPLAY', None)
408+
for dep in deps:
409+
assert dep not in sys.modules
400410

401411
# we should fast-track to Agg
402412
import matplotlib.pyplot as plt
403-
plt.get_backend() == 'agg'
404-
assert 'PyQt5' not in sys.modules
413+
assert plt.get_backend() == 'agg'
414+
for dep in deps:
415+
assert dep not in sys.modules
405416

406-
# make sure we really have pyqt installed
407-
import PyQt5 # noqa
408-
assert 'PyQt5' in sys.modules
417+
# make sure we really have dependencies installed
418+
for dep in deps:
419+
importlib.import_module(dep)
420+
assert dep in sys.modules
409421

410422
# try to switch and make sure we fail with ImportError
411423
try:
412-
plt.switch_backend('qt5agg')
424+
plt.switch_backend(backend)
413425
except ImportError:
414426
...
415427
else:
416428
sys.exit(1)
417429

418430

419431
@pytest.mark.skipif(sys.platform != "linux", reason="this a linux-only test")
420-
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
421-
def test_lazy_linux_headless():
422-
proc = _run_helper(_lazy_headless, timeout=_test_timeout, MPLBACKEND="")
432+
@pytest.mark.parametrize("env", _get_testable_interactive_backends())
433+
def test_lazy_linux_headless(env):
434+
proc = _run_helper(
435+
_lazy_headless,
436+
env.pop('MPLBACKEND'), env.pop("BACKEND_DEPS"),
437+
timeout=_test_timeout,
438+
**{**env, 'DISPLAY': '', 'WAYLAND_DISPLAY': ''}
439+
)
423440

424441

425442
def _qApp_warn_impl():

0 commit comments

Comments
 (0)