-
Notifications
You must be signed in to change notification settings - Fork 11
/
run_commit_tests.py
43 lines (38 loc) · 1.22 KB
/
run_commit_tests.py
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
33
34
35
36
37
38
39
40
41
42
43
import re
import sys
from subprocess import CalledProcessError, check_output
TEST_RE = re.compile(r"tests/.*test\w+\.py")
if __name__ == "__main__":
committed_files = (
check_output(["git", "--no-pager", "diff", "--name-only", "--cached"])
.decode()
.splitlines()
)
tests = [f for f in committed_files if TEST_RE.match(f)]
if tests:
print(f"Testing {tests} ...")
try:
print(
"\n".join(
check_output(
[
"pytest",
"--run-headless",
"-m",
"not unstable and not headed",
"-n",
"4",
*tests,
]
)
.decode()
.splitlines()
)
)
except CalledProcessError as exc:
error_lines = "\n".join(exc.output.decode().splitlines())
print("Error", exc.returncode)
print(error_lines)
# pass if no files are runnable
if exc.returncode != 5:
sys.exit(1)