-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
89 lines (76 loc) · 3 KB
/
run_tests.py
File metadata and controls
89 lines (76 loc) · 3 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
"""
Script to run all tests without external dependencies.
Usage: python run_tests.py
"""
import sys
import unittest
from pathlib import Path
import argparse
def run_all_tests():
"""Run all tests in the tests/ folder"""
# Add the project root to PYTHONPATH
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
print("=" * 60)
print("TEST EXECUTION - dot-env-handler")
print("=" * 60)
# Use discovery only
loader = unittest.TestLoader()
start_dir = project_root / "tests"
print(f"Discovering tests in: {start_dir}")
suite = loader.discover(str(start_dir), pattern="test_*.py")
# Run tests
runner = unittest.TextTestRunner(verbosity=2, failfast=False)
result = runner.run(suite)
# Print summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
print(f"Tests run: {result.testsRun}")
print(f"Successes: {result.testsRun - len(result.failures) - len(result.errors)}")
print(f"Failures: {len(result.failures)}")
print(f"Errors: {len(result.errors)}")
# Print failure details
if result.failures:
print("\nFAILURES:")
for test, traceback in result.failures:
print(f"\n• {test}:")
last_line = traceback.splitlines()[-1] if traceback else "Unknown error"
print(f" {last_line}")
if result.errors:
print("\nERRORS:")
for test, traceback in result.errors:
print(f"\n• {test}:")
last_line = traceback.splitlines()[-1] if traceback else "Unknown error"
print(f" {last_line}")
# Return 0 if all tests pass, 1 otherwise
return 0 if result.wasSuccessful() else 1
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run project tests")
parser.add_argument("--test", "-t", help="Run specific test (e.g., test_unit.TestHash)")
parser.add_argument("--module", "-m", help="Run specific module (e.g., test_unit)")
args = parser.parse_args()
if args.test:
# Run specific test
loader = unittest.TestLoader()
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
suite = loader.loadTestsFromName(args.test)
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
sys.exit(0 if result.wasSuccessful() else 1)
elif args.module:
# Run specific module
loader = unittest.TestLoader()
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
module_name = f"tests.{args.module}" if not args.module.startswith("tests.") else args.module
module = __import__(module_name, fromlist=[''])
suite = loader.loadTestsFromModule(module)
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
sys.exit(0 if result.wasSuccessful() else 1)
else:
# Run all tests
sys.exit(run_all_tests())