-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
63 lines (48 loc) · 1.66 KB
/
run_tests.py
File metadata and controls
63 lines (48 loc) · 1.66 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
#!/usr/bin/env python3
"""
Script to run all tests for the Notes application
"""
import sys
import unittest
from pathlib import Path
# Add root directory to path
root_dir = Path(__file__).parent
sys.path.insert(0, str(root_dir))
def run_all_tests():
"""Run all tests"""
print("[*] Running tests for Notes\n")
# Discover and load all tests
loader = unittest.TestLoader()
start_dir = root_dir / 'tests'
suite = loader.discover(start_dir, pattern='test_*.py')
# Run tests
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
# Print summary
print("\n" + "="*70)
print("TEST SUMMARY")
print("="*70)
print(f"Tests run: {result.testsRun}")
print(f"[OK] Passed: {result.testsRun - len(result.failures) - len(result.errors)}")
print(f"[FAIL] Failures: {len(result.failures)}")
print(f"[ERROR] Errors: {len(result.errors)}")
print(f"[SKIP] Skipped: {len(result.skipped)}")
print("="*70)
# Return 0 if all tests pass, 1 otherwise
return 0 if result.wasSuccessful() else 1
def run_specific_test(test_module):
"""Run a specific test module"""
print(f"[*] Running test: {test_module}\n")
loader = unittest.TestLoader()
suite = loader.loadTestsFromName(f'tests.{test_module}')
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
return 0 if result.wasSuccessful() else 1
if __name__ == '__main__':
if len(sys.argv) > 1:
# Esegui un test specifico
test_module = sys.argv[1]
sys.exit(run_specific_test(test_module))
else:
# Esegui tutti i test
sys.exit(run_all_tests())