From 98a4144a4197c2b96e4df7bfd9c386d4fbdb1f4f Mon Sep 17 00:00:00 2001 From: Tristan Rice Date: Mon, 10 Aug 2026 15:14:53 -0700 Subject: [PATCH] [Bugfix] Preserve non-logitproc entry points in tests (#51097) Signed-off-by: Tristan Rice --- .../logits_processors/test_custom_offline.py | 28 +++++++++++++++++++ tests/v1/logits_processors/utils.py | 13 +++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tests/v1/logits_processors/test_custom_offline.py b/tests/v1/logits_processors/test_custom_offline.py index 325ca48b59..302a72057e 100644 --- a/tests/v1/logits_processors/test_custom_offline.py +++ b/tests/v1/logits_processors/test_custom_offline.py @@ -1,9 +1,11 @@ # SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project +import importlib.metadata from typing import Any import pytest +import tests.v1.logits_processors.utils as logitproc_test_utils from tests.utils import create_new_process_for_each_test, set_random_seed from tests.v1.logits_processors.utils import ( DUMMY_LOGITPROC_ARG, @@ -42,6 +44,32 @@ sampling_params_list = [ ] +def test_fake_entrypoint_preserves_other_groups(monkeypatch): + other_group_entrypoints = object() + monkeypatch.setattr( + importlib.metadata, + "entry_points", + lambda **kwargs: other_group_entrypoints, + ) + monkeypatch.setattr( + logitproc_test_utils, "requires_spawn_multiprocessing", lambda: False + ) + + setup_fake_entrypoint(monkeypatch) + + logitproc_entrypoints = importlib.metadata.entry_points( + group=logitproc_test_utils.LOGITSPROCS_GROUP + ) + assert logitproc_entrypoints.names == [ + logitproc_test_utils.DUMMY_LOGITPROC_ENTRYPOINT + ] + assert ( + importlib.metadata.entry_points(group="another.entrypoint.group") + is other_group_entrypoints + ) + assert importlib.metadata.entry_points() is other_group_entrypoints + + def _run_test(kwargs: dict, logitproc_loaded: bool) -> None: """Compare `LLM` instance initialized with specified `kwargs` against reference `LLM` instance. diff --git a/tests/v1/logits_processors/utils.py b/tests/v1/logits_processors/utils.py index a2181d8e18..fb45b73c98 100644 --- a/tests/v1/logits_processors/utils.py +++ b/tests/v1/logits_processors/utils.py @@ -234,11 +234,6 @@ def register_fake_entrypoint(monkeypatch) -> str: return str(tmpdir) -def fake_entry_points(group: str) -> EntryPoints: - """Fake version of importlib.metadata.entry_points.""" - return EntryPoints(group) - - def setup_fake_entrypoint(monkeypatch) -> None: """Expose the dummy logitproc entrypoint for the current platform.""" if requires_spawn_multiprocessing(): @@ -248,5 +243,13 @@ def setup_fake_entrypoint(monkeypatch) -> None: import importlib.metadata + original_entry_points = importlib.metadata.entry_points + + def fake_entry_points(**kwargs): + group = kwargs.get("group") + if group == LOGITSPROCS_GROUP: + return EntryPoints(group) + return original_entry_points(**kwargs) + monkeypatch.setattr(importlib.metadata, "entry_points", fake_entry_points) monkeypatch.setenv("VLLM_WORKER_MULTIPROC_METHOD", "fork")