-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
68 lines (55 loc) · 1.78 KB
/
tests.py
File metadata and controls
68 lines (55 loc) · 1.78 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
62
63
64
65
66
67
68
# run_tests.py
import os
import subprocess
from pathlib import Path
import sys
def run_command(command, cwd):
"""Run a command in the specified directory and return the result"""
process = subprocess.run(
command,
cwd=cwd,
shell=True,
text=True,
capture_output=True
)
return process
def print_separator(text):
"""Print a separator with text"""
print(f"\n{'='*80}\n{text}\n{'='*80}")
def main():
# Get the absolute path to the projects directory
base_dir = Path(__file__).parent
projects_dir = base_dir / 'projects'
# Test commands for each project
test_configs = {
'flask-easy': 'python -m pytest --junitxml=unit.xml',
'flask-intermediate': 'python -m pytest --junitxml=unit.xml',
'flask-hard': 'flask --app manage.py test'
}
all_passed = True
results = {}
# Run tests for each project
for project, command in test_configs.items():
project_dir = projects_dir / project
print_separator(f"Running tests for project: {project}")
# Run the test command
result = run_command(command, str(project_dir))
results[project] = result
# Print output
print("\nOutput:")
print(result.stdout)
if result.stderr:
print("\nErrors:")
print(result.stderr)
# Check if tests passed
if result.returncode != 0:
all_passed = False
# Print final summary
print_separator("Test Summary")
for project, result in results.items():
status = "PASSED" if result.returncode == 0 else "FAILED"
print(f"{project}: {status}")
# Exit with appropriate status code
sys.exit(0 if all_passed else 1)
if __name__ == "__main__":
main()