#!/usr/bin/env python3
"""
Run all unit tests for the attendance application.
Usage:
python3 run_tests.py # Run all tests
python3 run_tests.py test_utils # Run specific test module
python3 run_tests.py -v # Verbose output
"""
import sys
import unittest
import os
# Add the parent directory to the path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def run_all_tests():
"""Run all unit tests."""
loader = unittest.TestLoader()
start_dir = 'attendance_app/tests'
suite = loader.discover(start_dir, pattern='test_*.py')
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
return 0 if result.wasSuccessful() else 1
def run_specific_test(test_name):
"""Run a specific test module."""
loader = unittest.TestLoader()
suite = loader.loadTestsFromName(f'attendance_app.tests.{test_name}')
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
return 0 if result.wasSuccessful() else 1
if __name__ == '__main__':
if len(sys.argv) > 1 and not sys.argv[1].startswith('-'):
# Run specific test
exit_code = run_specific_test(sys.argv[1])
else:
# Run all tests
exit_code = run_all_tests()
sys.exit(exit_code)