@@ -176,6 +176,11 @@ def pytest_addoption(parser):
176176 group .addoption ('--mpl-default-tolerance' , help = tolerance_help , action = 'store' )
177177 parser .addini ('mpl-default-tolerance' , help = tolerance_help )
178178
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+
179184
180185def pytest_configure (config ):
181186
@@ -232,6 +237,10 @@ def pytest_configure(config):
232237 config .getini ("mpl-default-tolerance" ) or
233238 "2" )
234239
240+ default_backend = (config .getoption ("--mpl-default-backend" ) or
241+ config .getini ("mpl-default-backend" ) or
242+ "agg" )
243+
235244 config .pluginmanager .register (ImageComparison (config ,
236245 baseline_dir = baseline_dir ,
237246 baseline_relative_dir = baseline_relative_dir ,
@@ -244,6 +253,7 @@ def pytest_configure(config):
244253 use_full_test_name = use_full_test_name ,
245254 default_style = default_style ,
246255 default_tolerance = default_tolerance ,
256+ default_backend = default_backend ,
247257 _hash_library_from_cli = _hash_library_from_cli ))
248258
249259 else :
@@ -304,6 +314,7 @@ def __init__(self,
304314 use_full_test_name = False ,
305315 default_style = 'classic' ,
306316 default_tolerance = 2 ,
317+ default_backend = 'agg' ,
307318 _hash_library_from_cli = False , # for backwards compatibility
308319 ):
309320 self .config = config
@@ -329,6 +340,7 @@ def __init__(self,
329340
330341 self .default_style = default_style
331342 self .default_tolerance = default_tolerance
343+ self .default_backend = default_backend
332344
333345 # Generate the containing dir for all test results
334346 if not self .results_dir :
@@ -731,7 +743,7 @@ def pytest_runtest_call(self, item): # noqa
731743
732744 style = compare .kwargs .get ('style' , self .default_style )
733745 remove_text = compare .kwargs .get ('remove_text' , False )
734- backend = compare .kwargs .get ('backend' , 'agg' )
746+ backend = compare .kwargs .get ('backend' , self . default_backend )
735747
736748 ext = self ._file_extension (item )
737749
0 commit comments