@@ -199,18 +199,22 @@ def _bisect_items(items: T.List[str], failing: str, fails: T.Callable[[T.List[st
199
199
return items
200
200
201
201
202
- def _reduce_tests (tests_path : Path , tests : T .List [str ], failing_test : str , * , trace = None ) -> T .List [str ]:
202
+ def _reduce_tests (tests_path : Path , tests : T .List [str ], failing_test : str ,
203
+ * , trace : bool = False , pytest_args : T .List [str ] = ()) -> T .List [str ]:
203
204
def fails (test_set : T .List [str ]):
204
- trial = _run_pytest (tests_path , ('--continue-on-collection-errors' ,), tests = test_set , trace = trace )
205
+ trial = _run_pytest (tests_path , (* pytest_args , '--continue-on-collection-errors' ),
206
+ tests = test_set , trace = trace )
205
207
return trial .get_outcome (failing_test ) == 'failed'
206
208
207
209
return _bisect_items (tests , failing_test , fails )
208
210
209
211
210
212
def _reduce_modules (tests_path : Path , tests : T .List [str ], failing_test : str ,
211
- modules : T .List [str ], failing_module : str , * , trace = None ) -> T .List [str ]:
213
+ modules : T .List [str ], failing_module : str ,
214
+ * , trace : bool = False , pytest_args : T .List [str ] = ()) -> T .List [str ]:
212
215
def fails (module_set : T .List [str ]):
213
- trial = _run_pytest (tests_path , ('--continue-on-collection-errors' ,), tests = tests , modules = module_set , trace = trace )
216
+ trial = _run_pytest (tests_path , (* pytest_args , '--continue-on-collection-errors' ,),
217
+ tests = tests , modules = module_set , trace = trace )
214
218
return trial .get_outcome (failing_test ) == 'failed'
215
219
216
220
return _bisect_items (modules , failing_module , fails )
@@ -224,6 +228,7 @@ def _parse_args():
224
228
ap = argparse .ArgumentParser ()
225
229
ap .add_argument ('--trace' , default = False , action = bool_action , help = 'show pytest outputs, etc.' )
226
230
ap .add_argument ('--save-to' , type = Path , help = 'file where to save results (JSON)' )
231
+ ap .add_argument ('--pytest-args' , type = str , default = '' , help = 'extra arguments to pass to pytest' )
227
232
ap .add_argument ('--version' , action = 'version' ,
228
233
version = f"%(prog)s v{ __version__ } (Python { '.' .join (map (str , sys .version_info [:3 ]))} )" )
229
234
ap .add_argument ('tests_path' , type = Path , help = 'tests file or directory' )
@@ -233,9 +238,10 @@ def _parse_args():
233
238
234
239
def main ():
235
240
args = _parse_args ()
241
+ pytest_args = args .pytest_args .split ()
236
242
237
243
print ("Running tests..." , flush = True )
238
- results = _run_pytest (args .tests_path , ('-x' , ), trace = args .trace )
244
+ results = _run_pytest (args .tests_path , (* pytest_args , '-x' ), trace = args .trace )
239
245
240
246
failed = results .get_first_failed ()
241
247
if failed is None :
@@ -254,14 +260,14 @@ def main():
254
260
if args .trace : print ()
255
261
print (f"Module \" { failed } \" 's collection failed; trying it by itself..." , flush = True )
256
262
failed_module = failed
257
- solo = _run_pytest ( args . tests_path , modules = [ failed_module ], trace = args . trace )
263
+ tests = None
258
264
else :
259
265
if args .trace : print ()
260
266
print (f"Test \" { failed } \" failed; trying it by itself..." , flush = True )
261
267
failed_module = results .get_module (failed )
268
+ tests = [failed ]
262
269
263
- solo = _run_pytest (args .tests_path , modules = [failed_module ], tests = [failed ], trace = args .trace )
264
-
270
+ solo = _run_pytest (args .tests_path , pytest_args , modules = [failed_module ], tests = tests , trace = args .trace )
265
271
if solo .get_outcome (failed ) != 'passed' :
266
272
print ("That also fails by itself!" , flush = True )
267
273
if args .save_to :
@@ -279,13 +285,14 @@ def main():
279
285
280
286
if args .trace : print ()
281
287
print ("Trying to reduce test set..." , flush = True )
282
- tests = _reduce_tests (args .tests_path , tests , failed , trace = args .trace )
288
+ tests = _reduce_tests (args .tests_path , tests , failed , trace = args .trace , pytest_args = pytest_args )
283
289
284
290
if args .trace : print ()
285
291
print ("Trying to reduce module set..." , flush = True )
286
292
287
293
modules = [m for m in results .get_modules () if m != failed_module ]
288
- modules = _reduce_modules (args .tests_path , tests if is_module else tests + [failed ], failed , modules , failed_module , trace = args .trace )
294
+ modules = _reduce_modules (args .tests_path , tests if is_module else tests + [failed ], failed ,
295
+ modules , failed_module , trace = args .trace , pytest_args = pytest_args )
289
296
290
297
if args .trace : print ()
291
298
print ("Reduced failure set:" )
0 commit comments