Skip to content

Commit 2c446e1

Browse files
committed
test.py: time each test
1 parent e6ae65b commit 2c446e1

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tests/__init__.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11

22
from concurrent.futures import ThreadPoolExecutor
3+
from dataclasses import dataclass
4+
from datetime import timedelta
35
import os
46
import sys
57
import subprocess
8+
from time import perf_counter
69
from typing import List # , Set, Dict, Tuple, Optional
710

811
from tests.util import *
@@ -200,18 +203,31 @@ def run(self, conf: Config) -> bool:
200203
return True
201204

202205

206+
@dataclass
207+
class TestResult:
208+
test: Test
209+
passed: bool
210+
time: timedelta
211+
212+
203213
def run_tests(conf: Config):
204214
if not conf.ignore_requirements:
205215
check(conf)
206216

207217
tests = [Test(td) for td in conf.project_dirs]
208218

209-
def run(tt: Test) -> tuple[Test, bool]:
210-
return tt, tt.run(conf)
219+
def run(test: Test) -> TestResult:
220+
start = perf_counter()
221+
passed = test.run(conf)
222+
end = perf_counter()
223+
time = timedelta(seconds=end - start)
224+
return TestResult(test=test, passed=passed, time=time)
211225

212226
with ThreadPoolExecutor() as executor:
213227
results = executor.map(run, tests)
214228

215-
if not all(result[1] for result in results):
216-
print(f"projects failed: {" ".join(result[0].name for result in results)}")
229+
for result in results:
230+
print(f"{result.test.name} took {result.time}")
231+
if not all(result.passed for result in results):
232+
print(f"projects failed: {" ".join(result.test.name for result in results)}")
217233
exit(1)

0 commit comments

Comments
 (0)