Skip to content

Commit

Permalink
- added tqdm-based progress bar;
Browse files Browse the repository at this point in the history
  • Loading branch information
jaltmayerpizzorno committed May 29, 2024
1 parent 7ba65a6 commit 033e50b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies = [
"pytest",
"py",
"pytest-forked",
"tqdm",
]

[project.urls]
Expand Down
22 changes: 14 additions & 8 deletions src/pytest_cleanslate/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import json
import sys
from .__version__ import __version__
import tqdm
import math


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


def _bisect_items(items: T.List[str], failing: str, fails: T.Callable[[T.List[str], str], bool]) -> T.List[str]:
def _bisect_items(items: T.List[str], failing: str, fails: T.Callable[[T.List[str], str], bool],
*, bar: "tqdm") -> T.List[str]:
assert failing not in items

while len(items) > 1:
print(f"... {len(items)}")
middle = len(items) // 2

bar.set_postfix({"remaining": len(items)})
bar.update()

if fails(items[:middle]+[failing]):
items = items[:middle]
continue
Expand All @@ -195,7 +200,9 @@ def _bisect_items(items: T.List[str], failing: str, fails: T.Callable[[T.List[st
if len(items) == 1 and fails([failing]):
items = []

print(f"... {len(items)}")
bar.set_postfix({"remaining": len(items)})
bar.update()

return items


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

return _bisect_items(tests, failing_test, fails)
with tqdm.tqdm(desc="Trying to reduce tests.....", total=math.ceil(math.log(len(tests), 2))) as bar:
return _bisect_items(tests, failing_test, fails, bar=bar)


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

return _bisect_items(modules, failing_module, fails)
with tqdm.tqdm(desc="Trying to reduce modules...", total=math.ceil(math.log(len(modules), 2))) as bar:
return _bisect_items(modules, failing_module, fails, bar=bar)


def _parse_args():
Expand Down Expand Up @@ -284,12 +293,9 @@ def main():
tests = tests[:-1]

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

if args.trace: print()
print("Trying to reduce module set...", flush=True)

modules = [m for m in results.get_modules() if m != failed_module]
modules = _reduce_modules(args.tests_path, tests if is_module else tests + [failed], failed,
modules, failed_module, trace=args.trace, pytest_args=pytest_args)
Expand Down

0 comments on commit 033e50b

Please sign in to comment.