@@ -59,7 +59,12 @@ def _get_testable_interactive_backends():
59
59
elif env ["MPLBACKEND" ].startswith ('wx' ) and sys .platform == 'darwin' :
60
60
# ignore on OSX because that's currently broken (github #16849)
61
61
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
+ )
63
68
return envs
64
69
65
70
@@ -396,32 +401,44 @@ def _lazy_headless():
396
401
import os
397
402
import sys
398
403
404
+ backend , deps = sys .argv [1 :]
405
+ deps = deps .split (',' )
406
+
399
407
# make it look headless
400
408
os .environ .pop ('DISPLAY' , None )
401
409
os .environ .pop ('WAYLAND_DISPLAY' , None )
410
+ for dep in deps :
411
+ assert dep not in sys .modules
402
412
403
413
# we should fast-track to Agg
404
414
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
407
418
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
411
423
412
424
# try to switch and make sure we fail with ImportError
413
425
try :
414
- plt .switch_backend ('qt5agg' )
426
+ plt .switch_backend (backend )
415
427
except ImportError :
416
428
...
417
429
else :
418
430
sys .exit (1 )
419
431
420
432
421
433
@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
+ )
425
442
426
443
427
444
def _qApp_warn_impl ():
0 commit comments