@@ -162,6 +162,14 @@ def pytest_addoption(parser):
162
162
parser .addini ('mpl-use-full-test-name' , help = "use fully qualified test name as the filename." ,
163
163
type = 'bool' )
164
164
165
+ style_help = "default style to use for tests, unless specified in the mpl_image_compare decorator"
166
+ group .addoption ('--mpl-default-style' , help = style_help , action = 'store' )
167
+ parser .addini ('mpl-default-style' , help = style_help )
168
+
169
+ tolerance_help = "default tolerance to use for tests, unless specified in the mpl_image_compare decorator"
170
+ group .addoption ('--mpl-default-tolerance' , help = tolerance_help , action = 'store' )
171
+ parser .addini ('mpl-default-tolerance' , help = tolerance_help )
172
+
165
173
166
174
def pytest_configure (config ):
167
175
@@ -202,6 +210,12 @@ def pytest_configure(config):
202
210
if results_dir is not None :
203
211
results_dir = os .path .abspath (results_dir )
204
212
213
+ default_style = (config .getoption ("--mpl-default-style" ) or
214
+ config .getini ("mpl-default-style" ))
215
+
216
+ default_tolerance = (config .getoption ("--mpl-default-tolerance" ) or
217
+ config .getini ("mpl-default-tolerance" ))
218
+
205
219
config .pluginmanager .register (ImageComparison (config ,
206
220
baseline_dir = baseline_dir ,
207
221
baseline_relative_dir = baseline_relative_dir ,
@@ -210,7 +224,9 @@ def pytest_configure(config):
210
224
hash_library = hash_library ,
211
225
generate_hash_library = generate_hash_lib ,
212
226
generate_summary = generate_summary ,
213
- results_always = results_always ))
227
+ results_always = results_always ,
228
+ default_style = default_style ,
229
+ default_tolerance = default_tolerance ))
214
230
215
231
else :
216
232
@@ -266,7 +282,9 @@ def __init__(self,
266
282
hash_library = None ,
267
283
generate_hash_library = None ,
268
284
generate_summary = None ,
269
- results_always = False
285
+ results_always = False ,
286
+ default_style = 'classic' ,
287
+ default_tolerance = 2
270
288
):
271
289
self .config = config
272
290
self .baseline_dir = baseline_dir
@@ -287,6 +305,9 @@ def __init__(self,
287
305
self .generate_summary = generate_summary
288
306
self .results_always = results_always
289
307
308
+ self .default_style = default_style
309
+ self .default_tolerance = default_tolerance
310
+
290
311
# Generate the containing dir for all test results
291
312
if not self .results_dir :
292
313
self .results_dir = Path (tempfile .mkdtemp (dir = self .results_dir ))
@@ -467,7 +488,7 @@ def compare_image_to_baseline(self, item, fig, result_dir, summary=None):
467
488
summary = {}
468
489
469
490
compare = get_compare (item )
470
- tolerance = compare .kwargs .get ('tolerance' , 2 )
491
+ tolerance = compare .kwargs .get ('tolerance' , self . default_tolerance )
471
492
472
493
ext = self ._file_extension (item )
473
494
@@ -683,7 +704,7 @@ def pytest_runtest_call(self, item): # noqa
683
704
from matplotlib .testing .decorators import ImageComparisonTest as MplImageComparisonTest
684
705
remove_ticks_and_titles = MplImageComparisonTest .remove_text
685
706
686
- style = compare .kwargs .get ('style' , 'classic' )
707
+ style = compare .kwargs .get ('style' , self . default_style )
687
708
remove_text = compare .kwargs .get ('remove_text' , False )
688
709
backend = compare .kwargs .get ('backend' , 'agg' )
689
710
0 commit comments