Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

1.4 KB
Raw Blame
import asyncio
from typing import Final

import pytest

import litellm
from litellm.rust_bridge import _native, execution
from litellm.rust_bridge.public_call import NativeCall
from tests.test_litellm_rust.responses.data import REQUEST
from tests.test_litellm_rust.support.callback_recorder import RecordingLogger
from tests.test_litellm_rust.support.recording_server import RecordingServer

pytestmark = pytest.mark.requires_rust_extension


@pytest.mark.asyncio
async def test_unstarted_call_has_no_provider_or_callback_effects(
    server: RecordingServer, monkeypatch: pytest.MonkeyPatch
) -> None:
    recorder: Final = RecordingLogger()
    server.expected_requests = 0
    monkeypatch.setattr(litellm, "ssl_verify", object())
    monkeypatch.setattr(litellm, "max_budget", 1.0)
    monkeypatch.setattr(litellm, "_current_cost", 2.0)
    kwargs: Final = {
        **REQUEST,
        "api_key": "test-key",
        "api_base": server.base_url,
        "callbacks": [recorder],
    }

    base: Final = {
        **REQUEST,
        "stream": None,
        "api_key": "test-key",
        "api_base": server.base_url,
        "custom_llm_provider": "openai",
        "extra_headers": None,
    }

    pending: Final = execution.asynchronous(_native.aresponses)(NativeCall(args=(), kwargs=kwargs, base=base))
    assert asyncio.iscoroutine(pending)
    pending.close()

    assert not server.requests
    assert not recorder.events