mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
Fix test_error_handling_integration for parallel test execution
The test was making real API calls instead of using mocks because the conftest.py reloads litellm at module scope, causing stale module references. The mock was patching the old reference while the actual code used the new one. Fix: Reload litellm.containers.main inside the test to get a fresh reference to base_llm_http_handler, then re-import create_container after the reload.
This commit is contained in:
parent
ab658d7d50
commit
59d3c75462
1 changed files with 23 additions and 13 deletions
|
|
@ -357,17 +357,27 @@ class TestContainerIntegration:
|
|||
|
||||
def test_error_handling_integration(self):
|
||||
"""Test error handling in the integration flow."""
|
||||
# Simulate an API error
|
||||
api_error = litellm.APIError(
|
||||
status_code=400,
|
||||
message="API Error occurred",
|
||||
llm_provider="openai",
|
||||
model=""
|
||||
)
|
||||
|
||||
with patch.object(litellm.main.base_llm_http_handler, 'container_create_handler', side_effect=api_error):
|
||||
import importlib
|
||||
import litellm.containers.main as containers_main_module
|
||||
|
||||
# Reload the module to ensure it has a fresh reference to base_llm_http_handler
|
||||
# after conftest reloads litellm
|
||||
importlib.reload(containers_main_module)
|
||||
|
||||
# Re-import the function after reload
|
||||
from litellm.containers.main import create_container as create_container_fresh
|
||||
|
||||
with patch('litellm.containers.main.base_llm_http_handler') as mock_handler:
|
||||
# Simulate an API error
|
||||
mock_handler.container_create_handler.side_effect = litellm.APIError(
|
||||
status_code=400,
|
||||
message="API Error occurred",
|
||||
llm_provider="openai",
|
||||
model=""
|
||||
)
|
||||
|
||||
with pytest.raises(litellm.APIError):
|
||||
create_container(
|
||||
create_container_fresh(
|
||||
name="Error Test Container",
|
||||
custom_llm_provider="openai"
|
||||
)
|
||||
|
|
@ -385,12 +395,12 @@ class TestContainerIntegration:
|
|||
name="Provider Test Container"
|
||||
)
|
||||
|
||||
with patch.object(litellm.main.base_llm_http_handler, 'container_create_handler', return_value=mock_response) as mock_handler:
|
||||
with patch('litellm.containers.main.base_llm_http_handler') as mock_handler:
|
||||
mock_handler.container_create_handler.return_value = mock_response
|
||||
|
||||
response = create_container(
|
||||
name="Provider Test Container",
|
||||
custom_llm_provider=provider
|
||||
)
|
||||
|
||||
assert response.name == "Provider Test Container"
|
||||
# Verify the mock was actually called (not making real API calls)
|
||||
mock_handler.assert_called_once()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue