forked from ai-dynamo/dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
56 lines (40 loc) · 1.57 KB
/
conftest.py
File metadata and controls
56 lines (40 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Block dynamo.vllm/sglang from shadowing the installed vllm/sglang.
Pytest collection puts components/src/dynamo on sys.path, which makes
`import vllm` resolve to dynamo.vllm. Spawned subprocesses (EngineCore,
sglang scheduler) inherit that and crash on `from vllm.v1 ...`.
"""
from __future__ import annotations
import importlib
import os
import sys
from pathlib import Path
# Seed sys.modules with the venv copies before pytest collection runs.
for _name in ("vllm", "sglang"):
try:
importlib.import_module(_name)
except ImportError:
pass
# Suppress ImportPathMismatchError when pytest later loads dynamo.vllm
# under the bare name "vllm".
os.environ.setdefault("PY_IGNORE_IMPORTMISMATCH", "1")
_BAD_DYNAMO_PATH = str(
Path(__file__).resolve().parent / "components" / "src" / "dynamo"
)
def _strip_bad_path() -> None:
while _BAD_DYNAMO_PATH in sys.path:
sys.path.remove(_BAD_DYNAMO_PATH)
# Strip the bad path before multiprocessing.spawn freezes sys.path for the
# child — catches re-insertions that happen during fixture/test execution.
try:
import multiprocessing.spawn as _mps
_orig_get_preparation_data = _mps.get_preparation_data
def _patched_get_preparation_data(name):
_strip_bad_path()
return _orig_get_preparation_data(name)
_mps.get_preparation_data = _patched_get_preparation_data
except Exception:
pass
def pytest_runtest_setup(item):
_strip_bad_path()