""" Pytest configuration and fixtures """ import pytest import requests import time from typing import Generator @pytest.fixture(scope="session") def api_available() -> bool: """Check if API is available before running tests""" try: response = requests.get("http://localhost:8000/health", timeout=5) return response.status_code == 200 except requests.exceptions.RequestException: return False @pytest.fixture(autouse=True) def skip_if_api_not_available(api_available): """Skip all tests if API is not available""" if not api_available: pytest.skip("API not available. Start the server with: python app_clean.py") @pytest.fixture def wait_for_api(): """Wait for API to be ready""" max_attempts = 30 for attempt in range(max_attempts): try: response = requests.get("http://localhost:8000/health", timeout=2) if response.status_code == 200: return True except requests.exceptions.RequestException: pass time.sleep(1) return False