@@ -210,7 +210,9 @@ def pytest_addoption(parser):
210
210
help = "directory containing reference files, relative to location where py.test is run" , action = 'store' )
211
211
group .addoption ('--arraydiff-default-format' ,
212
212
help = "Default format for the reference arrays (can be 'fits' or 'text' currently)" )
213
-
213
+ group .addoption ('--full-path-dir' , action = 'store_true' ,
214
+ help = "Storing the reference files inside nested "
215
+ "directories" )
214
216
215
217
def pytest_configure (config ):
216
218
@@ -228,20 +230,24 @@ def pytest_configure(config):
228
230
reference_dir = os .path .abspath (generate_dir )
229
231
230
232
default_format = config .getoption ("--arraydiff-default-format" ) or 'text'
233
+ full_path_dir = config .getoption ("--full-path-dir" ) or False
231
234
232
235
config .pluginmanager .register (ArrayComparison (config ,
233
236
reference_dir = reference_dir ,
234
237
generate_dir = generate_dir ,
235
- default_format = default_format ))
238
+ default_format = default_format ,
239
+ full_path_dir = full_path_dir ))
236
240
237
241
238
242
class ArrayComparison (object ):
239
243
240
- def __init__ (self , config , reference_dir = None , generate_dir = None , default_format = 'text' ):
244
+ def __init__ (self , config , reference_dir = None , generate_dir = None ,
245
+ default_format = 'text' , full_path_dir = False ):
241
246
self .config = config
242
247
self .reference_dir = reference_dir
243
248
self .generate_dir = generate_dir
244
249
self .default_format = default_format
250
+ self .full_path_dir = full_path_dir
245
251
246
252
def pytest_runtest_setup (self , item ):
247
253
@@ -340,11 +346,16 @@ def item_function_wrapper(*args, **kwargs):
340
346
raise Exception (msg )
341
347
342
348
else :
343
- 1 / 0
344
- if not os .path .exists (self .generate_dir ):
345
- os .makedirs (self .generate_dir )
349
+ if self .full_path_dir :
350
+ generate_dir = os .path .join (
351
+ self .generate_dir , item .location [0 ].replace ('.py' , '' ))
352
+ else :
353
+ generate_dir = self .generate_dir
354
+ if not os .path .exists (generate_dir ):
355
+ os .makedirs (generate_dir )
346
356
347
- FORMATS [file_format ].write (os .path .abspath (os .path .join (self .generate_dir , filename )), array , ** write_kwargs )
357
+ FORMATS [file_format ].write (os .path .abspath (os .path .join (
358
+ generate_dir , filename )), array , ** write_kwargs )
348
359
349
360
pytest .skip ("Skipping test, since generating data" )
350
361
0 commit comments