@@ -176,6 +176,11 @@ def pytest_addoption(parser):
176
176
group .addoption ('--mpl-default-tolerance' , help = tolerance_help , action = 'store' )
177
177
parser .addini ('mpl-default-tolerance' , help = tolerance_help )
178
178
179
+ msg = "default backend to use for tests, unless specified in the mpl_image_compare decorator"
180
+ option = "mpl-default-backend"
181
+ group .addoption (f"--{ option } " , help = msg , action = "store" )
182
+ parser .addini (option , help = msg )
183
+
179
184
180
185
def pytest_configure (config ):
181
186
@@ -232,6 +237,10 @@ def pytest_configure(config):
232
237
config .getini ("mpl-default-tolerance" ) or
233
238
"2" )
234
239
240
+ default_backend = (config .getoption ("--mpl-default-backend" ) or
241
+ config .getini ("mpl-default-backend" ) or
242
+ "agg" )
243
+
235
244
config .pluginmanager .register (ImageComparison (config ,
236
245
baseline_dir = baseline_dir ,
237
246
baseline_relative_dir = baseline_relative_dir ,
@@ -244,6 +253,7 @@ def pytest_configure(config):
244
253
use_full_test_name = use_full_test_name ,
245
254
default_style = default_style ,
246
255
default_tolerance = default_tolerance ,
256
+ default_backend = default_backend ,
247
257
_hash_library_from_cli = _hash_library_from_cli ))
248
258
249
259
else :
@@ -304,6 +314,7 @@ def __init__(self,
304
314
use_full_test_name = False ,
305
315
default_style = 'classic' ,
306
316
default_tolerance = 2 ,
317
+ default_backend = 'agg' ,
307
318
_hash_library_from_cli = False , # for backwards compatibility
308
319
):
309
320
self .config = config
@@ -329,6 +340,7 @@ def __init__(self,
329
340
330
341
self .default_style = default_style
331
342
self .default_tolerance = default_tolerance
343
+ self .default_backend = default_backend
332
344
333
345
# Generate the containing dir for all test results
334
346
if not self .results_dir :
@@ -731,7 +743,7 @@ def pytest_runtest_call(self, item): # noqa
731
743
732
744
style = compare .kwargs .get ('style' , self .default_style )
733
745
remove_text = compare .kwargs .get ('remove_text' , False )
734
- backend = compare .kwargs .get ('backend' , 'agg' )
746
+ backend = compare .kwargs .get ('backend' , self . default_backend )
735
747
736
748
ext = self ._file_extension (item )
737
749
0 commit comments