forked from project-orion-2025/rigel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_executor.py
More file actions
61 lines (54 loc) · 2.06 KB
/
Copy pathtest_executor.py
File metadata and controls
61 lines (54 loc) · 2.06 KB
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
54
55
56
57
58
59
60
61
import glob
import os
import pytest
from io import StringIO
from contextlib import redirect_stdout
# test_folders = glob.glob('tests**/', recursive=True)
# for folder in test_folders:
# test_files = glob.glob(os.path.join(folder, 'test_*.py'))
# if test_files:
# pytest.main(test_files)
def run_tests_and_summarize():
test_folders = glob.glob('tests**/', recursive=True)
passed_tests = []
failed_tests = []
# Capture pytest output
pytest_output = StringIO()
with redirect_stdout(pytest_output):
for folder in test_folders:
test_files = glob.glob(os.path.join(folder, 'test_*.py'))
for test_file in test_files:
# Run pytest for each test file and capture results
result = pytest.main([test_file])
if result == 0: # 0 means all tests passed
passed_tests.append(test_file)
else:
failed_tests.append(test_file)
# Extract failed test case names and error messages
failed_test_details = []
pytest_output.seek(0)
lines = pytest_output.readlines()
for i, line in enumerate(lines):
if line.startswith("FAILED"):
test_name = line.split("::")[0].strip()
error_message = []
# Collect relevant error lines following the failure
for j in range(i + 1, len(lines)):
if lines[j].strip() == "" or lines[j].startswith("="): # Stop on empty or pytest separator lines
break
error_message.append(lines[j].strip())
failed_test_details.append((test_name, "\n".join(error_message)))
# Summary Report
print("\nTest Summary")
print("------------")
for test in passed_tests:
print(f"✅ {test}")
for test, _ in failed_test_details:
print(f"❌ {test}")
# Aggregator
print("\nAggregator:")
print("------------")
print(f"✅ Passed: {len(passed_tests)}")
print(f"❌ Failed: {len(failed_test_details)}\n")
if __name__ == "__main__":
run_tests_and_summarize()