Skip to content

Commit 033e50b

Browse files
- added tqdm-based progress bar;
1 parent 7ba65a6 commit 033e50b

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies = [
2121
"pytest",
2222
"py",
2323
"pytest-forked",
24+
"tqdm",
2425
]
2526

2627
[project.urls]

src/pytest_cleanslate/reduce.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import json
55
import sys
66
from .__version__ import __version__
7+
import tqdm
8+
import math
79

810

911
PYTEST_ARGS = ('-qq', '-p', 'pytest_cleanslate.reduce')
@@ -174,13 +176,16 @@ def _run_pytest(tests_path: Path, extra_args=(), *,
174176
return Results(results)
175177

176178

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]:
178181
assert failing not in items
179182

180183
while len(items) > 1:
181-
print(f"... {len(items)}")
182184
middle = len(items) // 2
183185

186+
bar.set_postfix({"remaining": len(items)})
187+
bar.update()
188+
184189
if fails(items[:middle]+[failing]):
185190
items = items[:middle]
186191
continue
@@ -195,7 +200,9 @@ def _bisect_items(items: T.List[str], failing: str, fails: T.Callable[[T.List[st
195200
if len(items) == 1 and fails([failing]):
196201
items = []
197202

198-
print(f"... {len(items)}")
203+
bar.set_postfix({"remaining": len(items)})
204+
bar.update()
205+
199206
return items
200207

201208

@@ -206,7 +213,8 @@ def fails(test_set: T.List[str]):
206213
tests=test_set, trace=trace)
207214
return trial.get_outcome(failing_test) == 'failed'
208215

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)
210218

211219

212220
def _reduce_modules(tests_path: Path, tests: T.List[str], failing_test: str,
@@ -217,7 +225,8 @@ def fails(module_set: T.List[str]):
217225
tests=tests, modules=module_set, trace=trace)
218226
return trial.get_outcome(failing_test) == 'failed'
219227

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)
221230

222231

223232
def _parse_args():
@@ -284,12 +293,9 @@ def main():
284293
tests = tests[:-1]
285294

286295
if args.trace: print()
287-
print("Trying to reduce test set...", flush=True)
288296
tests = _reduce_tests(args.tests_path, tests, failed, trace=args.trace, pytest_args=pytest_args)
289297

290298
if args.trace: print()
291-
print("Trying to reduce module set...", flush=True)
292-
293299
modules = [m for m in results.get_modules() if m != failed_module]
294300
modules = _reduce_modules(args.tests_path, tests if is_module else tests + [failed], failed,
295301
modules, failed_module, trace=args.trace, pytest_args=pytest_args)

0 commit comments

Comments
 (0)