File size: 1,077 Bytes
8c0b652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
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