Skip to content

Commit bf20956

Browse files
qandrewAndrew Xia
authored andcommitted
try more
Signed-off-by: Andrew Xia <axia@fb.com>
1 parent 7d49b2f commit bf20956

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

tests/entrypoints/openai/test_response_api_with_harmony.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33

44
import json
5+
import os
56
import time
67

78
import pytest
@@ -771,31 +772,35 @@ async def test_output_messages_enabled(client: OpenAI, model_name: str,
771772

772773
@pytest.fixture(scope="module")
773774
def server_with_mock(monkeypatch_module: pytest.MonkeyPatch, tmp_path_factory):
774-
import tempfile
775775
import textwrap
776776

777777
args = ["--enforce-eager", "--tool-server", "demo"]
778778

779-
# Create a temporary startup script that patches render_for_completion
779+
# Create a sitecustomize.py that patches render_for_completion
780+
# Python automatically imports sitecustomize on startup if it's in sys.path
780781
tmp_dir = tmp_path_factory.mktemp("test_setup")
781-
startup_script = tmp_dir / "mock_startup.py"
782-
startup_script.write_text(textwrap.dedent("""
783-
import sys
784-
from unittest.mock import patch
785-
786-
# Mock render_for_completion to return a large token list
787-
def mock_render_for_completion(messages):
788-
return list(range(1000000)) # Return 1M tokens for testing
789-
790-
# Patch it at module level before it's imported
791-
patch('vllm.entrypoints.harmony_utils.render_for_completion',
792-
mock_render_for_completion).start()
782+
sitecustomize = tmp_dir / "sitecustomize.py"
783+
sitecustomize.write_text(textwrap.dedent("""
784+
import os
785+
if os.environ.get('VLLM_TEST_MOCK_LARGE_PROMPT') == '1':
786+
from unittest.mock import patch
787+
788+
# Mock render_for_completion to return a large token list
789+
def mock_render_for_completion(messages):
790+
return list(range(1000000)) # Return 1M tokens for testing
791+
792+
# Patch it at module level before it's imported
793+
patch('vllm.entrypoints.harmony_utils.render_for_completion',
794+
mock_render_for_completion).start()
793795
"""))
794796

795797
with monkeypatch_module.context() as m:
796798
m.setenv("VLLM_ENABLE_RESPONSES_API_STORE", "1")
797-
# Use PYTHONSTARTUP to run our mock setup before the server starts
798-
m.setenv("PYTHONSTARTUP", str(startup_script))
799+
m.setenv("VLLM_TEST_MOCK_LARGE_PROMPT", "1")
800+
# Add tmp_dir to PYTHONPATH so sitecustomize.py is found
801+
current_pythonpath = os.environ.get("PYTHONPATH", "")
802+
new_pythonpath = f"{tmp_dir}:{current_pythonpath}" if current_pythonpath else str(tmp_dir)
803+
m.setenv("PYTHONPATH", new_pythonpath)
799804
with RemoteOpenAIServer(MODEL_NAME, args) as remote_server:
800805
yield remote_server
801806

0 commit comments

Comments
 (0)