[Bugfix] Fix VLLM_ENFORCE_STRICT_TOOL_CALLING mutation in tests (#49846)
Signed-off-by: Yifan Zong <yzong@redhat.com>
yzong-rh committed
Jul 27, 2026 at 12:12 UTC
3f47a8384d90a6e29b05b18d84942f8d7c895def
3 files changed
+26
-44
tests/parser/test_include_reasoning.py
+6
-22
@@ -7,31 +7,15 @@ streaming (parse_delta), and ParsableContext.append_output() paths.
7
"""
8
9
import json
10
-import os
10
11
import pytest
12
14
-_STRICT_TOOL_CALLING_ENV = "VLLM_ENFORCE_STRICT_TOOL_CALLING"
15
-_STRICT_TOOL_CALLING_ENV_VALUE = os.environ.get(_STRICT_TOOL_CALLING_ENV)
16
-os.environ[_STRICT_TOOL_CALLING_ENV] = "0"
17
-
18
-from vllm.entrypoints.openai.chat_completion.protocol import ( # noqa: E402
19
- ChatCompletionRequest,
20
-)
21
-from vllm.entrypoints.openai.engine.protocol import DeltaMessage # noqa: E402
22
-from vllm.entrypoints.openai.responses.protocol import ResponsesRequest # noqa: E402
23
-from vllm.parser.abstract_parser import DelegatingParser # noqa: E402
24
-from vllm.reasoning.basic_parsers import BaseThinkingReasoningParser # noqa: E402
25
-from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser # noqa: E402
26
-
27
-
28
-@pytest.fixture(scope="module", autouse=True)
29
-def restore_strict_tool_calling_env():
30
- yield
31
- if _STRICT_TOOL_CALLING_ENV_VALUE is None:
32
- os.environ.pop(_STRICT_TOOL_CALLING_ENV, None)
33
- else:
34
- os.environ[_STRICT_TOOL_CALLING_ENV] = _STRICT_TOOL_CALLING_ENV_VALUE
13
+from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
14
+from vllm.entrypoints.openai.engine.protocol import DeltaMessage
15
+from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
16
+from vllm.parser.abstract_parser import DelegatingParser
17
+from vllm.reasoning.basic_parsers import BaseThinkingReasoningParser
18
+from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser
19
20
21
class ThinkReasoningParser(BaseThinkingReasoningParser):
tests/parser/test_parse.py
+12
-22
@@ -2,34 +2,24 @@
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
import json
5
-import os
5
from types import SimpleNamespace
6
7
import pytest
8
10
-_STRICT_TOOL_CALLING_ENV = "VLLM_ENFORCE_STRICT_TOOL_CALLING"
11
-_STRICT_TOOL_CALLING_ENV_VALUE = os.environ.get(_STRICT_TOOL_CALLING_ENV)
12
-os.environ[_STRICT_TOOL_CALLING_ENV] = "0"
13
-
14
-from vllm.entrypoints.openai.chat_completion.protocol import ( # noqa: E402
15
- ChatCompletionRequest,
16
-)
17
-from vllm.entrypoints.openai.responses.protocol import ResponsesRequest # noqa: E402
18
-from vllm.parser.abstract_parser import DelegatingParser # noqa: E402
19
-from vllm.parser.utils import count_history_tool_calls # noqa: E402
20
-from vllm.reasoning.basic_parsers import ( # noqa: E402
21
- BaseThinkingReasoningParser,
22
-)
23
-from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser # noqa: E402
9
+from vllm.entrypoints.openai.chat_completion.protocol import ChatCompletionRequest
10
+from vllm.entrypoints.openai.responses.protocol import ResponsesRequest
11
+from vllm.parser.abstract_parser import DelegatingParser
12
+from vllm.parser.utils import count_history_tool_calls
13
+from vllm.reasoning.basic_parsers import BaseThinkingReasoningParser
14
+from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser
15
16
26
-@pytest.fixture(scope="module", autouse=True)
27
-def restore_strict_tool_calling_env():
28
- yield
29
- if _STRICT_TOOL_CALLING_ENV_VALUE is None:
30
- os.environ.pop(_STRICT_TOOL_CALLING_ENV, None)
31
- else:
32
- os.environ[_STRICT_TOOL_CALLING_ENV] = _STRICT_TOOL_CALLING_ENV_VALUE
17
+@pytest.fixture(autouse=True)
18
+def enable_hermes_required_named_parsing(monkeypatch):
19
+ # With VLLM_ENFORCE_STRICT_TOOL_CALLING (default on), Hermes sets
20
+ # supports_required_and_named=False and uses structural-tag guided tool
21
+ # calling. Force it True to test the non-guided JSON required/named parse path.
22
+ monkeypatch.setattr(Hermes2ProToolParser, "supports_required_and_named", True)
23
24
25
class ThinkReasoningParser(BaseThinkingReasoningParser):
tests/parser/test_streaming.py
+8
@@ -14,6 +14,14 @@ from vllm.reasoning.basic_parsers import BaseThinkingReasoningParser
14
from vllm.tool_parsers.hermes_tool_parser import Hermes2ProToolParser
15
16
17
+@pytest.fixture(autouse=True)
18
+def enable_hermes_required_named_parsing(monkeypatch):
19
+ # With VLLM_ENFORCE_STRICT_TOOL_CALLING (default on), Hermes sets
20
+ # supports_required_and_named=False and uses structural-tag guided tool
21
+ # calling. Force it True to test the non-guided JSON required/named parse path.
22
+ monkeypatch.setattr(Hermes2ProToolParser, "supports_required_and_named", True)
23
+
24
+
25
class ThinkReasoningParser(BaseThinkingReasoningParser):
26
@property
27
def start_token(self) -> str: