4
4
import json
5
5
import sys
6
6
from .__version__ import __version__
7
+ import tqdm
8
+ import math
7
9
8
10
9
11
PYTEST_ARGS = ('-qq' , '-p' , 'pytest_cleanslate.reduce' )
@@ -174,13 +176,16 @@ def _run_pytest(tests_path: Path, extra_args=(), *,
174
176
return Results (results )
175
177
176
178
177
- def _bisect_items (items : T .List [str ], failing : str , fails : T .Callable [[T .List [str ], str ], bool ]) -> T .List [str ]:
179
+ def _bisect_items (items : T .List [str ], failing : str , fails : T .Callable [[T .List [str ], str ], bool ],
180
+ * , bar : "tqdm" ) -> T .List [str ]:
178
181
assert failing not in items
179
182
180
183
while len (items ) > 1 :
181
- print (f"... { len (items )} " )
182
184
middle = len (items ) // 2
183
185
186
+ bar .set_postfix ({"remaining" : len (items )})
187
+ bar .update ()
188
+
184
189
if fails (items [:middle ]+ [failing ]):
185
190
items = items [:middle ]
186
191
continue
@@ -195,7 +200,9 @@ def _bisect_items(items: T.List[str], failing: str, fails: T.Callable[[T.List[st
195
200
if len (items ) == 1 and fails ([failing ]):
196
201
items = []
197
202
198
- print (f"... { len (items )} " )
203
+ bar .set_postfix ({"remaining" : len (items )})
204
+ bar .update ()
205
+
199
206
return items
200
207
201
208
@@ -206,7 +213,8 @@ def fails(test_set: T.List[str]):
206
213
tests = test_set , trace = trace )
207
214
return trial .get_outcome (failing_test ) == 'failed'
208
215
209
- return _bisect_items (tests , failing_test , fails )
216
+ with tqdm .tqdm (desc = "Trying to reduce tests....." , total = math .ceil (math .log (len (tests ), 2 ))) as bar :
217
+ return _bisect_items (tests , failing_test , fails , bar = bar )
210
218
211
219
212
220
def _reduce_modules (tests_path : Path , tests : T .List [str ], failing_test : str ,
@@ -217,7 +225,8 @@ def fails(module_set: T.List[str]):
217
225
tests = tests , modules = module_set , trace = trace )
218
226
return trial .get_outcome (failing_test ) == 'failed'
219
227
220
- return _bisect_items (modules , failing_module , fails )
228
+ with tqdm .tqdm (desc = "Trying to reduce modules..." , total = math .ceil (math .log (len (modules ), 2 ))) as bar :
229
+ return _bisect_items (modules , failing_module , fails , bar = bar )
221
230
222
231
223
232
def _parse_args ():
@@ -284,12 +293,9 @@ def main():
284
293
tests = tests [:- 1 ]
285
294
286
295
if args .trace : print ()
287
- print ("Trying to reduce test set..." , flush = True )
288
296
tests = _reduce_tests (args .tests_path , tests , failed , trace = args .trace , pytest_args = pytest_args )
289
297
290
298
if args .trace : print ()
291
- print ("Trying to reduce module set..." , flush = True )
292
-
293
299
modules = [m for m in results .get_modules () if m != failed_module ]
294
300
modules = _reduce_modules (args .tests_path , tests if is_module else tests + [failed ], failed ,
295
301
modules , failed_module , trace = args .trace , pytest_args = pytest_args )
0 commit comments