@@ -156,6 +156,14 @@ def pytest_addoption(parser):
156
156
parser .addini ('mpl-use-full-test-name' , help = "use fully qualified test name as the filename." ,
157
157
type = 'bool' )
158
158
159
+ style_help = "default style to use for tests, unless specified in the mpl_image_compare decorator"
160
+ group .addoption ('--mpl-default-style' , help = style_help , action = 'store' )
161
+ parser .addini ('mpl-default-style' , help = style_help )
162
+
163
+ tolerance_help = "default tolerance to use for tests, unless specified in the mpl_image_compare decorator"
164
+ group .addoption ('--mpl-default-tolerance' , help = tolerance_help , action = 'store' )
165
+ parser .addini ('mpl-default-tolerance' , help = tolerance_help )
166
+
159
167
160
168
def pytest_configure (config ):
161
169
@@ -196,6 +204,12 @@ def pytest_configure(config):
196
204
if results_dir is not None :
197
205
results_dir = os .path .abspath (results_dir )
198
206
207
+ default_style = (config .getoption ("--mpl-default-style" ) or
208
+ config .getini ("mpl-default-style" ))
209
+
210
+ default_tolerance = (config .getoption ("--mpl-default-tolerance" ) or
211
+ config .getini ("mpl-default-tolerance" ))
212
+
199
213
config .pluginmanager .register (ImageComparison (config ,
200
214
baseline_dir = baseline_dir ,
201
215
baseline_relative_dir = baseline_relative_dir ,
@@ -204,7 +218,9 @@ def pytest_configure(config):
204
218
hash_library = hash_library ,
205
219
generate_hash_library = generate_hash_lib ,
206
220
generate_summary = generate_summary ,
207
- results_always = results_always ))
221
+ results_always = results_always ,
222
+ default_style = default_style ,
223
+ default_tolerance = default_tolerance ))
208
224
209
225
else :
210
226
@@ -260,7 +276,9 @@ def __init__(self,
260
276
hash_library = None ,
261
277
generate_hash_library = None ,
262
278
generate_summary = None ,
263
- results_always = False
279
+ results_always = False ,
280
+ default_style = 'classic' ,
281
+ default_tolerance = 2
264
282
):
265
283
self .config = config
266
284
self .baseline_dir = baseline_dir
@@ -281,6 +299,9 @@ def __init__(self,
281
299
self .generate_summary = generate_summary
282
300
self .results_always = results_always
283
301
302
+ self .default_style = default_style
303
+ self .default_tolerance = default_tolerance
304
+
284
305
# Generate the containing dir for all test results
285
306
if not self .results_dir :
286
307
self .results_dir = Path (tempfile .mkdtemp (dir = self .results_dir ))
@@ -451,7 +472,7 @@ def compare_image_to_baseline(self, item, fig, result_dir, summary=None):
451
472
summary = {}
452
473
453
474
compare = get_compare (item )
454
- tolerance = compare .kwargs .get ('tolerance' , 2 )
475
+ tolerance = compare .kwargs .get ('tolerance' , self . default_tolerance )
455
476
savefig_kwargs = compare .kwargs .get ('savefig_kwargs' , {})
456
477
457
478
baseline_image_ref = self .obtain_baseline_image (item , result_dir )
@@ -612,7 +633,7 @@ def pytest_runtest_call(self, item): # noqa
612
633
from matplotlib .testing .decorators import ImageComparisonTest as MplImageComparisonTest
613
634
remove_ticks_and_titles = MplImageComparisonTest .remove_text
614
635
615
- style = compare .kwargs .get ('style' , 'classic' )
636
+ style = compare .kwargs .get ('style' , self . default_style )
616
637
remove_text = compare .kwargs .get ('remove_text' , False )
617
638
backend = compare .kwargs .get ('backend' , 'agg' )
618
639
0 commit comments