def skip_if_no_db():
    """Skip tests that require a database if connection is not available."""
    # Use a test database URL, trying the environment first, then fallback to localhost
    test_db_url = os.environ.get(
        "TEST_DATABASE_URL", "postgresql://airweave:airweave1234!@localhost:5432/airweave"
    )

    # Parse the URL to get the connection details
    parts = test_db_url.split("://")[1].split("@")
    creds = parts[0].split(":")
    host_parts = parts[1].split("/")
    host_port = host_parts[0].split(":")
    db_name = host_parts[1] if len(host_parts) > 1 else "postgres"

    user = creds[0]
    password = creds[1] if len(creds) > 1 else ""
    host = host_port[0]
    port = int(host_port[1]) if len(host_port) > 1 else 5432

    try:
        # For simplicity, use a simple sync check rather than async in this fixture
        import psycopg2

        psycopg2.connect(dbname=db_name, user=user, password=password, host=host, port=port).close()

        # If we get here, connection was successful
        return True
    except Exception as e:
        pytest.skip(f"Database connection not available: {e}")
Skip tests that require a database if connection is not available.
backend/tests/conftest.py