mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
Make unnecessary to pass extra arg for mock object
Modify `mock_patch_acompletion` to be a context manager instead of a function that returns a mock object. This way, the mock object is created and yielded by the context manager, and the test function doesn't need to pass the mock object as an argument.
This commit is contained in:
parent
4dfadb0cf4
commit
6ec058711a
1 changed files with 6 additions and 3 deletions
|
@ -2,6 +2,7 @@ import sys, os
|
|||
import traceback
|
||||
from unittest import mock
|
||||
from dotenv import load_dotenv
|
||||
import contextlib
|
||||
|
||||
load_dotenv()
|
||||
import os, io
|
||||
|
@ -37,6 +38,7 @@ token = "sk-1234"
|
|||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def mock_patch_acompletion():
|
||||
async def side_effect(*args, **kwargs):
|
||||
return {
|
||||
|
@ -50,10 +52,11 @@ def mock_patch_acompletion():
|
|||
],
|
||||
}
|
||||
|
||||
return mock.patch(
|
||||
with mock.patch(
|
||||
"litellm.proxy.proxy_server.llm_router.acompletion",
|
||||
side_effect=side_effect,
|
||||
)
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
|
@ -125,7 +128,7 @@ def test_chat_completion_azure(client_no_auth):
|
|||
|
||||
|
||||
@mock_patch_acompletion()
|
||||
def test_openai_deployments_model_chat_completions_azure(_mock_acompletion, client_no_auth):
|
||||
def test_openai_deployments_model_chat_completions_azure(client_no_auth):
|
||||
global headers
|
||||
try:
|
||||
# Your test data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue