forked from facebookincubator/ft_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_run_all.py
53 lines (45 loc) · 1.35 KB
/
test_run_all.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
44
45
46
47
48
49
50
51
52
53
# Copyright (c) Meta Platforms, Inc. and affiliates.
# pyre-unsafe
import os
import subprocess
import sys
def run_test(filename):
print(f"Running {filename}...")
f_head, f_tail = os.path.splitext(filename)
if f_tail != ".py":
raise ValueError(f"filename `{filename}` is not a Python (.py) file")
module = f"ft_utils.tests.{f_head}"
result = subprocess.run(
[sys.executable, "-m", module], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
if result.returncode != 0:
print(f"{module} failed:")
print(result.stdout.decode())
print(result.stderr.decode())
return False
print(f"{module} passed:")
print(result.stdout.decode())
print(result.stderr.decode())
return True
def invoke_main():
test_dir = os.path.dirname(__file__)
test_files = [
f
for f in os.listdir(test_dir)
if f.startswith("test_") or f.endswith("_bench.py")
]
all_passed = True
for test_file in test_files:
if "array" in test_file:
continue # These crash for now.
if "test_run_all" in test_file:
continue # Recursion.
if not run_test(test_file):
all_passed = False
if all_passed:
print("TEST OK")
else:
print("TESTS FAILED")
sys.exit(1)
if __name__ == "__main__":
invoke_main()