diff --git a/poetry.lock b/poetry.lock index e3f3fea1321..aa2d6879321 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1271,6 +1271,21 @@ typing-extensions = {version = ">=4.6.0", markers = "python_version < \"3.13\""} [package.extras] test = ["pytest (>=6)"] +[[package]] +name = "execnet" +version = "2.1.2" +description = "execnet: rapid multi-Python deployment" +optional = false +python-versions = ">=3.8" +groups = ["dev"] +files = [ + {file = "execnet-2.1.2-py3-none-any.whl", hash = "sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec"}, + {file = "execnet-2.1.2.tar.gz", hash = "sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd"}, +] + +[package.extras] +testing = ["hatch", "pre-commit", "pytest", "tox"] + [[package]] name = "fakeredis" version = "2.33.0" @@ -5541,22 +5556,25 @@ packaging = ">=17.1" pytest = ">=7.2" [[package]] -name = "pytest-retry" -version = "1.7.0" -description = "Adds the ability to retry flaky tests in CI environments" +name = "pytest-xdist" +version = "3.8.0" +description = "pytest xdist plugin for distributed testing, most importantly across multiple CPUs" optional = false python-versions = ">=3.9" groups = ["dev"] files = [ - {file = "pytest_retry-1.7.0-py3-none-any.whl", hash = "sha256:a2dac85b79a4e2375943f1429479c65beb6c69553e7dae6b8332be47a60954f4"}, - {file = "pytest_retry-1.7.0.tar.gz", hash = "sha256:f8d52339f01e949df47c11ba9ee8d5b362f5824dff580d3870ec9ae0057df80f"}, + {file = "pytest_xdist-3.8.0-py3-none-any.whl", hash = "sha256:202ca578cfeb7370784a8c33d6d05bc6e13b4f25b5053c30a152269fd10f0b88"}, + {file = "pytest_xdist-3.8.0.tar.gz", hash = "sha256:7e578125ec9bc6050861aa93f2d59f1d8d085595d6551c2c90b6f4fad8d3a9f1"}, ] [package.dependencies] +execnet = ">=2.1" pytest = ">=7.0.0" [package.extras] -dev = ["black", "flake8", "isort", "mypy"] +psutil = ["psutil (>=3.0)"] +setproctitle = ["setproctitle"] +testing = ["filelock"] [[package]] name = "python-dateutil" @@ -7950,4 +7968,4 @@ utils = ["numpydoc"] [metadata] lock-version = "2.1" python-versions = ">=3.9,<4.0" -content-hash = "d99036fc86de60170dde4a1a9b3f9fdac6eb3610edb6177e70ca86133b71703e" +content-hash = "808c804f4b78ac91fe6fa060b976b7d03e3ad5316f2ac33bad4976bd284aeef4" diff --git a/tests/test_litellm/llms/custom_httpx/test_http_handler.py b/tests/test_litellm/llms/custom_httpx/test_http_handler.py index b0011fd8f76..caf90dce6c8 100644 --- a/tests/test_litellm/llms/custom_httpx/test_http_handler.py +++ b/tests/test_litellm/llms/custom_httpx/test_http_handler.py @@ -358,38 +358,40 @@ async def test_async_handler_with_shared_session(): @pytest.mark.asyncio async def test_get_async_httpx_client_with_shared_session(): """Test get_async_httpx_client with shared session""" - from litellm.llms.custom_httpx.http_handler import get_async_httpx_client + from litellm.llms.custom_httpx.http_handler import get_async_httpx_client, AsyncHTTPHandler as AsyncHTTPHandlerReload from litellm.types.utils import LlmProviders - + # Create a mock shared session mock_session = MockClientSession() - + # Test with shared session client = get_async_httpx_client( llm_provider=LlmProviders.ANTHROPIC, shared_session=mock_session # type: ignore ) - + # Verify the client was created successfully assert client is not None - assert isinstance(client, AsyncHTTPHandler) + # Import locally to avoid stale reference after module reload in conftest + assert isinstance(client, AsyncHTTPHandlerReload) @pytest.mark.asyncio async def test_get_async_httpx_client_without_shared_session(): """Test get_async_httpx_client without shared session (backward compatibility)""" - from litellm.llms.custom_httpx.http_handler import get_async_httpx_client + from litellm.llms.custom_httpx.http_handler import get_async_httpx_client, AsyncHTTPHandler as AsyncHTTPHandlerReload from litellm.types.utils import LlmProviders - + # Test without shared session client = get_async_httpx_client( llm_provider=LlmProviders.ANTHROPIC, shared_session=None ) - + # Verify the client was created successfully assert client is not None - assert isinstance(client, AsyncHTTPHandler) + # Import locally to avoid stale reference after module reload in conftest + assert isinstance(client, AsyncHTTPHandlerReload) @pytest.mark.asyncio @@ -450,31 +452,32 @@ def test_shared_session_parameter_in_completion(): @pytest.mark.asyncio async def test_session_reuse_integration(): """Integration test for session reuse functionality""" - from litellm.llms.custom_httpx.http_handler import get_async_httpx_client + from litellm.llms.custom_httpx.http_handler import get_async_httpx_client, AsyncHTTPHandler as AsyncHTTPHandlerReload from litellm.types.utils import LlmProviders - + # Create a mock session mock_session = MockClientSession() - + # Create two clients with the same session client1 = get_async_httpx_client( llm_provider=LlmProviders.ANTHROPIC, shared_session=mock_session # type: ignore ) - + client2 = get_async_httpx_client( llm_provider=LlmProviders.OPENAI, shared_session=mock_session # type: ignore ) - + # Both clients should be created successfully assert client1 is not None assert client2 is not None - + # Both should be AsyncHTTPHandler instances - assert isinstance(client1, AsyncHTTPHandler) - assert isinstance(client2, AsyncHTTPHandler) - + # Import locally to avoid stale reference after module reload in conftest + assert isinstance(client1, AsyncHTTPHandlerReload) + assert isinstance(client2, AsyncHTTPHandlerReload) + # Clean up await client1.close() await client2.close()