Unverified Commit ff625465 authored by KrishnanPrash's avatar KrishnanPrash Committed by GitHub
Browse files

ci: Adding Unit Tests for vLLM (--custom-jinja-template) (#3362)

parent a5371bfc
......@@ -77,7 +77,13 @@ jobs:
azure_acr_hostname: ${{ secrets.AZURE_ACR_HOSTNAME }}
azure_acr_user: ${{ secrets.AZURE_ACR_USER }}
azure_acr_password: ${{ secrets.AZURE_ACR_PASSWORD }}
- name: Run tests
- name: Run unit tests
if: ${{ matrix.platform.arch != 'arm64' }}
uses: ./.github/actions/pytest
with:
image_tag: ${{ steps.build-image.outputs.image_tag }}
pytest_marks: "unit and vllm and gpu_1"
- name: Run e2e tests
if: ${{ matrix.platform.arch != 'arm64' }}
uses: ./.github/actions/pytest
with:
......
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Conftest for dynamo backend unit tests.
Handles conditional test collection to prevent import errors when backend
frameworks are not installed in the current container.
"""
import importlib.util
def pytest_ignore_collect(collection_path, config):
"""Skip collecting backend test files if their framework isn't installed.
Checks test file naming pattern: test_<backend>_*.py
"""
filename = collection_path.name
# Map test file prefixes to required modules
backend_requirements = {
"test_vllm_": "vllm",
"test_sglang_": "sglang",
"test_trtllm_": "tensorrt_llm",
}
for prefix, required_module in backend_requirements.items():
if filename.startswith(prefix):
if importlib.util.find_spec(required_module) is None:
return True # Module not available, skip this file
return None # Not a backend test or module available
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Unit tests for vLLM backend components."""
import re
import sys
from pathlib import Path
import pytest
from dynamo.vllm.args import parse_args
# Get path relative to this test file
TEST_DIR = Path(__file__).parent.parent
JINJA_TEMPLATE_PATH = str(TEST_DIR / "serve" / "fixtures" / "custom_template.jinja")
pytestmark = [
pytest.mark.unit,
pytest.mark.vllm,
pytest.mark.gpu_1,
pytest.mark.pre_merge,
]
def test_custom_jinja_template_invalid_path(monkeypatch):
"""Test that invalid file path raises FileNotFoundError."""
invalid_path = "/nonexistent/path/to/template.jinja"
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.vllm",
"--model",
"Qwen/Qwen3-0.6B",
"--custom-jinja-template",
invalid_path,
],
)
with pytest.raises(
FileNotFoundError,
match=re.escape(f"Custom Jinja template file not found: {invalid_path}"),
):
parse_args()
def test_custom_jinja_template_valid_path(monkeypatch):
"""Test that valid absolute path is stored correctly."""
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.vllm",
"--model",
"Qwen/Qwen3-0.6B",
"--custom-jinja-template",
JINJA_TEMPLATE_PATH,
],
)
config = parse_args()
assert config.custom_jinja_template == JINJA_TEMPLATE_PATH, (
f"Expected custom_jinja_template value to be {JINJA_TEMPLATE_PATH}, "
f"got {config.custom_jinja_template}"
)
def test_custom_jinja_template_env_var_expansion(monkeypatch):
"""Test that environment variables in paths are expanded by Python code."""
jinja_dir = str(TEST_DIR / "serve" / "fixtures")
monkeypatch.setenv("JINJA_DIR", jinja_dir)
cli_path = "$JINJA_DIR/custom_template.jinja"
monkeypatch.setattr(
sys,
"argv",
[
"dynamo.vllm",
"--model",
"Qwen/Qwen3-0.6B",
"--custom-jinja-template",
cli_path,
],
)
config = parse_args()
assert "$JINJA_DIR" not in config.custom_jinja_template
assert config.custom_jinja_template == JINJA_TEMPLATE_PATH, (
f"Expected custom_jinja_template value to be {JINJA_TEMPLATE_PATH}, "
f"got {config.custom_jinja_template}"
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment