@@ -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
@@ -396,32 +401,44 @@ def _lazy_headless():
396401 import os
397402 import sys
398403
404+ backend , deps = sys .argv [1 :]
405+ deps = deps .split (',' )
406+
399407 # make it look headless
400408 os .environ .pop ('DISPLAY' , None )
401409 os .environ .pop ('WAYLAND_DISPLAY' , None )
410+ for dep in deps :
411+ assert dep not in sys .modules
402412
403413 # we should fast-track to Agg
404414 import matplotlib .pyplot as plt
405- plt .get_backend () == 'agg'
406- assert 'PyQt5' not in sys .modules
415+ assert plt .get_backend () == 'agg'
416+ for dep in deps :
417+ assert dep not in sys .modules
407418
408- # make sure we really have pyqt installed
409- import PyQt5 # noqa
410- assert 'PyQt5' in sys .modules
419+ # make sure we really have dependencies installed
420+ for dep in deps :
421+ importlib .import_module (dep )
422+ assert dep in sys .modules
411423
412424 # try to switch and make sure we fail with ImportError
413425 try :
414- plt .switch_backend ('qt5agg' )
426+ plt .switch_backend (backend )
415427 except ImportError :
416428 ...
417429 else :
418430 sys .exit (1 )
419431
420432
421433@pytest .mark .skipif (sys .platform != "linux" , reason = "this a linux-only test" )
422- @pytest .mark .backend ('Qt5Agg' , skip_on_importerror = True )
423- def test_lazy_linux_headless ():
424- proc = _run_helper (_lazy_headless , timeout = _test_timeout , MPLBACKEND = "" )
434+ @pytest .mark .parametrize ("env" , _get_testable_interactive_backends ())
435+ def test_lazy_linux_headless (env ):
436+ proc = _run_helper (
437+ _lazy_headless ,
438+ env .pop ('MPLBACKEND' ), env .pop ("BACKEND_DEPS" ),
439+ timeout = _test_timeout ,
440+ ** {** env , 'DISPLAY' : '' , 'WAYLAND_DISPLAY' : '' }
441+ )
425442
426443
427444def _qApp_warn_impl ():
0 commit comments