#!/bin/bash # A script to automate running integration tests locally. # It starts the FastAPI server, runs the tests, and then shuts down the server. echo "--- Starting AI Hub Server for Integration Tests ---" # Start the uvicorn server in the background uvicorn app.main:app --host 127.0.0.1 --port 8000 & # Get the Process ID (PID) of the background server SERVER_PID=$! # Define a cleanup function to be called on exit cleanup() { echo "--- Shutting Down Server (PID: $SERVER_PID) ---" kill $SERVER_PID } # Register the cleanup function to run when the script exits # This ensures the server is stopped even if tests fail or script is interrupted (Ctrl+C) trap cleanup EXIT echo "Server started with PID: $SERVER_PID. Waiting for it to initialize..." # Wait a few seconds to ensure the server is fully up and running sleep 5 echo "--- Running Integration Test Script ---" # Execute the Python integration test script pytest -s integration_tests/test_integration.py # Capture the exit code of the test script TEST_EXIT_CODE=$? # The 'trap' will automatically call the cleanup function now. # Exit with the same code as the test script (0 for success, non-zero for failure). exit $TEST_EXIT_CODE