Skip to content

Commit c66562d

Browse files
fix(tests): clear envs cache in VLLM_MAX_N_SEQUENCES tests
Signed-off-by: jperezde <jperezde@redhat.com>
1 parent 81a735e commit c66562d

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

tests/entrypoints/openai/chat_completion/test_chat.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,10 +1022,16 @@ def test_chat_completion_request_n_parameter_various_values():
10221022
)
10231023

10241024

1025-
def test_chat_completion_request_n_parameter_exceeds_default_limit():
1025+
def test_chat_completion_request_n_parameter_exceeds_default_limit(
1026+
monkeypatch: pytest.MonkeyPatch,
1027+
):
10261028
"""Test that n values exceeding the default limit are rejected."""
10271029
import vllm.envs as envs
10281030

1031+
monkeypatch.delenv("VLLM_MAX_N_SEQUENCES", raising=False)
1032+
if hasattr(envs.__getattr__, "cache_clear"):
1033+
envs.__getattr__.cache_clear()
1034+
10291035
max_n = envs.VLLM_MAX_N_SEQUENCES
10301036
request = ChatCompletionRequest(
10311037
model="test-model",
@@ -1041,10 +1047,16 @@ def test_chat_completion_request_n_parameter_exceeds_default_limit():
10411047
)
10421048

10431049

1044-
def test_chat_completion_request_n_parameter_at_limit():
1050+
def test_chat_completion_request_n_parameter_at_limit(
1051+
monkeypatch: pytest.MonkeyPatch,
1052+
):
10451053
"""Test that n at exactly the limit is accepted."""
10461054
import vllm.envs as envs
10471055

1056+
monkeypatch.delenv("VLLM_MAX_N_SEQUENCES", raising=False)
1057+
if hasattr(envs.__getattr__, "cache_clear"):
1058+
envs.__getattr__.cache_clear()
1059+
10481060
max_n = envs.VLLM_MAX_N_SEQUENCES
10491061
request = ChatCompletionRequest(
10501062
model="test-model",
@@ -1064,7 +1076,11 @@ def test_chat_completion_request_n_parameter_custom_limit(
10641076
monkeypatch: pytest.MonkeyPatch,
10651077
):
10661078
"""Test that VLLM_MAX_N_SEQUENCES env var overrides the default limit."""
1079+
import vllm.envs as envs
1080+
10671081
monkeypatch.setenv("VLLM_MAX_N_SEQUENCES", "128")
1082+
if hasattr(envs.__getattr__, "cache_clear"):
1083+
envs.__getattr__.cache_clear()
10681084

10691085
request = ChatCompletionRequest(
10701086
model="test-model",
@@ -1093,8 +1109,16 @@ def test_chat_completion_request_n_parameter_custom_limit(
10931109
)
10941110

10951111

1096-
def test_chat_completion_request_n_parameter_massive_value():
1112+
def test_chat_completion_request_n_parameter_massive_value(
1113+
monkeypatch: pytest.MonkeyPatch,
1114+
):
10971115
"""Test that astronomically large n values are rejected (CVE fix)."""
1116+
import vllm.envs as envs
1117+
1118+
monkeypatch.delenv("VLLM_MAX_N_SEQUENCES", raising=False)
1119+
if hasattr(envs.__getattr__, "cache_clear"):
1120+
envs.__getattr__.cache_clear()
1121+
10981122
request = ChatCompletionRequest(
10991123
model="test-model",
11001124
messages=[{"role": "user", "content": "Test"}],

tests/test_envs.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,16 @@ def test_custom_value(self, monkeypatch: pytest.MonkeyPatch):
475475

476476
assert envs.VLLM_MAX_N_SEQUENCES == 128
477477

478-
def test_sampling_params_respects_limit(self):
478+
def test_sampling_params_respects_limit(
479+
self, monkeypatch: pytest.MonkeyPatch,
480+
):
479481
"""Test that SamplingParams rejects n above the limit."""
480482
from vllm.sampling_params import SamplingParams
481483

484+
monkeypatch.delenv("VLLM_MAX_N_SEQUENCES", raising=False)
485+
if hasattr(envs.__getattr__, "cache_clear"):
486+
envs.__getattr__.cache_clear()
487+
482488
max_n = envs.VLLM_MAX_N_SEQUENCES
483489
SamplingParams(n=max_n)
484490

0 commit comments

Comments
 (0)