-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathcli.py
More file actions
32 lines (28 loc) · 931 Bytes
/
cli.py
File metadata and controls
32 lines (28 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import argparse
import json
def list_slowest_tests() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--durations-path",
help=(
"Path to the file in which durations are stored, "
"default is .test_durations in the current working directory"
),
default=".test_durations",
type=argparse.FileType(),
)
parser.add_argument(
"-c",
"--count",
help="How many slowest to list",
default=10,
type=int,
)
args = parser.parse_args()
return _list_slowest_tests(json.load(args.durations_path), args.count)
def _list_slowest_tests(durations: "dict[str, float]", count: int) -> None:
slowest_tests = tuple(
sorted(durations.items(), key=lambda item: item[1], reverse=True)
)[:count]
for test, duration in slowest_tests:
print(f"{duration:.2f} {test}") # noqa: T201