@@ -270,9 +270,10 @@ def test_weighted_twist_average():
270270
271271def test_save_plot_pdf ():
272272
273+ os .environ ['MPLBACKEND' ] = 'Agg'
273274 try :
274275 import matplotlib .pyplot # noqa: F401
275- except ImportError :
276+ except ( ImportError , RuntimeError ) :
276277 pytest .skip ('matplotlib not available' )
277278
278279 cwd = Path .cwd ()
@@ -283,7 +284,7 @@ def test_save_plot_pdf():
283284 if os .path .exists (plot_file ):
284285 os .remove (plot_file )
285286
286- command = (f'{ sys .executable } { QMCA_EXE } -t -q e -e 5 '
287+ command = (f'MPLBACKEND=Agg { sys .executable } { QMCA_EXE } -t -q e -e 5 '
287288 f'--image-prefix { prefix } --image-format pdf --nowarn *scalar*' )
288289 out ,err ,rc = execute (command )
289290 assert rc == 0
@@ -297,9 +298,10 @@ def test_save_plot_pdf():
297298
298299def test_save_plot_png_default ():
299300
301+ os .environ ['MPLBACKEND' ] = 'Agg'
300302 try :
301303 import matplotlib .pyplot # noqa: F401
302- except ImportError :
304+ except ( ImportError , RuntimeError ) :
303305 pytest .skip ('matplotlib not available' )
304306
305307 cwd = Path .cwd ()
@@ -310,7 +312,7 @@ def test_save_plot_png_default():
310312 if os .path .exists (plot_file ):
311313 os .remove (plot_file )
312314
313- command = (f'{ sys .executable } { QMCA_EXE } -t -q e -e 5 '
315+ command = (f'MPLBACKEND=Agg { sys .executable } { QMCA_EXE } -t -q e -e 5 '
314316 f'--image-prefix { prefix } --image --nowarn *scalar*' )
315317 out ,err ,rc = execute (command )
316318 assert rc == 0
0 commit comments