From 3f47a8384d90a6e29b05b18d84942f8d7c895def Mon Sep 17 00:00:00 2001 From: yzong-rh Date: Mon, 27 Jul 2026 12:12:14 -0400 Subject: [PATCH] [Bugfix] Fix VLLM_ENFORCE_STRICT_TOOL_CALLING mutation in tests (#49846) Signed-off-by: Yifan Zong --- tests/parser/test_include_reasoning.py | 28 +++++---------------- tests/parser/test_parse.py | 34 +++++++++----------------- tests/parser/test_streaming.py | 8 ++++++ 3 files changed, 26 insertions(+), 44 deletions(-) diff --git a/tests/parser/test_include_reasoning.py b/tests/parser/test_include_reasoning.py index 3d1893577ef..a75b3517356 100644 --- a/tests/parser/test_include_reasoning.py +++ b/tests/parser/test_include_reasoning.py @@ -7,31 +7,15 @@ streaming (parse_delta), and ParsableContext.append_output() paths. """ import json -import os import pytest -_STRICT_TOOL_CALLING_ENV = "VLLM_ENFORCE_STRICT_TOOL_CALLING" -_STRICT_TOOL_CALLING_ENV_VALUE = os.environ.get(_STRICT_TOOL_CALLING_ENV) -os.environ[_STRICT_TOOL_CALLING_ENV] = "0" - -from vllm.entrypoints.openai.chat_completion.protocol import ( # noqa: E402 - ChatCompletionRequest, -) -from vllm.entrypoints.openai.engine.protocol import DeltaMessage # noqa: E402 -from vllm.entrypoints.openai.responses.protocol import ResponsesRequest # noqa: E402 -from vllm.parser.abstract_parser import DelegatingParser # noqa: E402 -from vllm.reasoning.basic_parsers import BaseThinkingReasoningParser # noqa: E402 -from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser # noqa: E402 - - -@pytest.fixture(scope="module", autouse=True) -def restore_strict_tool_calling_env(): - yield - if _STRICT_TOOL_CALLING_ENV_VALUE is None: - os.environ.pop(_STRICT_TOOL_CALLING_ENV, None) - else: - os.environ[_STRICT_TOOL_CALLING_ENV] = _STRICT_TOOL_CALLING_ENV_VALUE +from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest +from vllm.entrypoints.openai.engine.protocol import DeltaMessage +from vllm.entrypoints.openai.responses.protocol import ResponsesRequest +from vllm.parser.abstract_parser import DelegatingParser +from vllm.reasoning.basic_parsers import BaseThinkingReasoningParser +from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser class ThinkReasoningParser(BaseThinkingReasoningParser): diff --git a/tests/parser/test_parse.py b/tests/parser/test_parse.py index 2a34ac7eea7..2379b8a4c2b 100644 --- a/tests/parser/test_parse.py +++ b/tests/parser/test_parse.py @@ -2,34 +2,24 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project import json -import os from types import SimpleNamespace import pytest -_STRICT_TOOL_CALLING_ENV = "VLLM_ENFORCE_STRICT_TOOL_CALLING" -_STRICT_TOOL_CALLING_ENV_VALUE = os.environ.get(_STRICT_TOOL_CALLING_ENV) -os.environ[_STRICT_TOOL_CALLING_ENV] = "0" - -from vllm.entrypoints.openai.chat_completion.protocol import ( # noqa: E402 - ChatCompletionRequest, -) -from vllm.entrypoints.openai.responses.protocol import ResponsesRequest # noqa: E402 -from vllm.parser.abstract_parser import DelegatingParser # noqa: E402 -from vllm.parser.utils import count_history_tool_calls # noqa: E402 -from vllm.reasoning.basic_parsers import ( # noqa: E402 - BaseThinkingReasoningParser, -) -from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser # noqa: E402 +from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest +from vllm.entrypoints.openai.responses.protocol import ResponsesRequest +from vllm.parser.abstract_parser import DelegatingParser +from vllm.parser.utils import count_history_tool_calls +from vllm.reasoning.basic_parsers import BaseThinkingReasoningParser +from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser -@pytest.fixture(scope="module", autouse=True) -def restore_strict_tool_calling_env(): - yield - if _STRICT_TOOL_CALLING_ENV_VALUE is None: - os.environ.pop(_STRICT_TOOL_CALLING_ENV, None) - else: - os.environ[_STRICT_TOOL_CALLING_ENV] = _STRICT_TOOL_CALLING_ENV_VALUE +@pytest.fixture(autouse=True) +def enable_hermes_required_named_parsing(monkeypatch): + # With VLLM_ENFORCE_STRICT_TOOL_CALLING (default on), Hermes sets + # supports_required_and_named=False and uses structural-tag guided tool + # calling. Force it True to test the non-guided JSON required/named parse path. + monkeypatch.setattr(Hermes2ProToolParser, "supports_required_and_named", True) class ThinkReasoningParser(BaseThinkingReasoningParser): diff --git a/tests/parser/test_streaming.py b/tests/parser/test_streaming.py index 1e3cca57d6d..619aa0e491a 100644 --- a/tests/parser/test_streaming.py +++ b/tests/parser/test_streaming.py @@ -14,6 +14,14 @@ from vllm.reasoning.basic_parsers import BaseThinkingReasoningParser from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser +@pytest.fixture(autouse=True) +def enable_hermes_required_named_parsing(monkeypatch): + # With VLLM_ENFORCE_STRICT_TOOL_CALLING (default on), Hermes sets + # supports_required_and_named=False and uses structural-tag guided tool + # calling. Force it True to test the non-guided JSON required/named parse path. + monkeypatch.setattr(Hermes2ProToolParser, "supports_required_and_named", True) + + class ThinkReasoningParser(BaseThinkingReasoningParser): @property def start_token(self) -> str: