#!/usr/bin/env python3 """ Comprehensive test runner for MCP AI Data Scientist system. Provides different test execution modes and coverage reporting. """ import argparse import subprocess import sys import os from pathlib import Path def run_command(cmd, description): """Run a command and handle errors.""" print(f"\n{'='*60}") print(f"Running: {description}") print(f"Command: {' '.join(cmd)}") print(f"{'='*60}") result = subprocess.run(cmd, capture_output=False) if result.returncode != 0: print(f"❌ {description} failed with exit code {result.returncode}") return False else: print(f"✅ {description} completed successfully") return True def main(): parser = argparse.ArgumentParser(description="Run MCP AI Data Scientist tests") parser.add_argument("--unit", action="store_true", help="Run unit tests only") parser.add_argument("--integration", action="store_true", help="Run integration tests only") parser.add_argument("--performance", action="store_true", help="Run performance tests only") parser.add_argument("--security", action="store_true", help="Run security tests only") parser.add_argument("--all", action="store_true", help="Run all tests (default)") parser.add_argument("--coverage", action="store_true", help="Generate coverage report") parser.add_argument("--html-report", action="store_true", help="Generate HTML coverage report") parser.add_argument("--parallel", "-n", type=int, help="Run tests in parallel (number of workers)") parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output") parser.add_argument("--fast", action="store_true", help="Skip slow tests") args = parser.parse_args() # Default to running all tests if no specific type is selected if not any([args.unit, args.integration, args.performance, args.security]): args.all = True # Base pytest command cmd = ["python", "-m", "pytest"] # Add verbosity if args.verbose: cmd.extend(["-v", "-s"]) # Add parallel execution if args.parallel: cmd.extend(["-n", str(args.parallel)]) # Add coverage if requested if args.coverage or args.html_report: cmd.extend([ "--cov=mcp_servers", "--cov=orchestrator", "--cov=streamlit_app", "--cov=shared", "--cov-report=term-missing" ]) if args.html_report: cmd.append("--cov-report=html:htmlcov") # Skip slow tests if requested if args.fast: cmd.extend(["-m", "not slow"]) # Test selection test_commands = [] if args.unit or args.all: unit_cmd = cmd + ["-m", "unit", "tests/"] test_commands.append((unit_cmd, "Unit Tests")) if args.integration or args.all: integration_cmd = cmd + ["-m", "integration", "tests/"] test_commands.append((integration_cmd, "Integration Tests")) if args.performance or args.all: perf_cmd = cmd + ["-m", "performance", "tests/"] test_commands.append((perf_cmd, "Performance Tests")) if args.security or args.all: security_cmd = cmd + ["-m", "security", "tests/"] test_commands.append((security_cmd, "Security Tests")) # If no specific test type and not all, run everything if not test_commands and not args.all: test_commands.append((cmd + ["tests/"], "All Tests")) # Run tests all_passed = True for test_cmd, description in test_commands: if not run_command(test_cmd, description): all_passed = False # Generate coverage report summary if args.coverage or args.html_report: print(f"\n{'='*60}") print("Coverage Report Summary") print(f"{'='*60}") if args.html_report: print("📊 HTML coverage report generated in: htmlcov/index.html") # Run coverage report subprocess.run(["python", "-m", "coverage", "report", "--show-missing"]) # Final summary print(f"\n{'='*60}") if all_passed: print("🎉 All tests passed successfully!") sys.exit(0) else: print("❌ Some tests failed. Check the output above.") sys.exit(1) if __name__ == "__main__": main()