Aniworld/run_api_tests.py

80 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""
Simple test execution script for API tests.
Run this from the command line to execute all API tests.
"""
import subprocess
import sys
import os
def main():
"""Main execution function."""
print("🚀 Aniworld API Test Executor")
print("=" * 40)
# Get the directory of this script
script_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.join(script_dir, '..', '..')
# Change to project root
os.chdir(project_root)
print(f"📁 Working directory: {os.getcwd()}")
print(f"🐍 Python version: {sys.version}")
# Try to run the comprehensive test runner
test_runner = os.path.join('tests', 'unit', 'web', 'run_api_tests.py')
if os.path.exists(test_runner):
print(f"\n🧪 Running comprehensive test suite...")
try:
result = subprocess.run([sys.executable, test_runner], capture_output=False)
return result.returncode
except Exception as e:
print(f"❌ Error running comprehensive tests: {e}")
# Fallback to individual test files
print(f"\n🔄 Falling back to individual test execution...")
test_files = [
os.path.join('tests', 'unit', 'web', 'test_api_endpoints.py'),
os.path.join('tests', 'integration', 'test_api_integration.py')
]
total_failures = 0
for test_file in test_files:
if os.path.exists(test_file):
print(f"\n📋 Running {test_file}...")
try:
result = subprocess.run([
sys.executable, '-m', 'unittest',
test_file.replace('/', '.').replace('\\', '.').replace('.py', ''),
'-v'
], capture_output=False, cwd=project_root)
if result.returncode != 0:
total_failures += 1
print(f"❌ Test file {test_file} had failures")
else:
print(f"✅ Test file {test_file} passed")
except Exception as e:
print(f"❌ Error running {test_file}: {e}")
total_failures += 1
else:
print(f"⚠️ Test file not found: {test_file}")
# Final summary
print(f"\n{'='*40}")
if total_failures == 0:
print("🎉 All tests completed successfully!")
return 0
else:
print(f"{total_failures} test file(s) had issues")
return 1
if __name__ == '__main__':
exit_code = main()
sys.exit(exit_code)