Skip to content

Commit 8f83c78

Browse files
committed
Removing backend_requirements and having separate conftest file for each backend
Signed-off-by: pvijayakrish <[email protected]>
1 parent 8a193da commit 8f83c78

File tree

3 files changed

+30
-132
lines changed

3 files changed

+30
-132
lines changed

components/src/dynamo/sglang/tests/conftest.py

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
"""Conftest for dynamo backend unit tests.
5-
6-
Handles conditional test collection to prevent import errors when backend
7-
frameworks are not installed in the current container.
4+
"""Conftest for dynamo.sglang unit tests only.
5+
Handles conditional test collection to prevent import errors when the sglang
6+
framework is not installed in the current container.
87
"""
98

109
import importlib.util
@@ -14,62 +13,29 @@
1413

1514

1615
def pytest_ignore_collect(collection_path, config):
17-
"""Skip collecting backend test files if their framework isn't installed.
18-
19-
Checks test file naming pattern: test_<backend>_*.py
16+
"""Skip collecting sglang test files if sglang module isn't installed.
17+
Checks test file naming pattern: test_sglang_*.py
2018
"""
2119
filename = collection_path.name
22-
23-
# Map test file prefixes to required modules
24-
backend_requirements = {
25-
"test_vllm_": "vllm",
26-
"test_sglang_": "sglang",
27-
"test_trtllm_": "tensorrt_llm",
28-
}
29-
30-
for prefix, required_module in backend_requirements.items():
31-
if filename.startswith(prefix):
32-
if importlib.util.find_spec(required_module) is None:
33-
return True # Module not available, skip this file
34-
35-
return None # Not a backend test or module available
20+
if filename.startswith("test_sglang_"):
21+
if importlib.util.find_spec("sglang") is None:
22+
return True # sglang not available, skip this file
23+
return None
3624

3725

3826
def make_cli_args_fixture(module_name: str):
39-
"""Create a pytest fixture for mocking CLI arguments for a backend.
40-
41-
The returned fixture supports two call styles:
42-
43-
1. Explicit:
44-
mock_vllm_cli("--model", "gpt-2", "--custom-jinja-template", "path.jinja")
45-
46-
2. Kwargs (auto-converts underscores to hyphens):
47-
mock_vllm_cli(model="gpt-2", custom_jinja_template="path.jinja")
48-
49-
Both produce: ["dynamo.vllm", "--model", "gpt-2", "--custom-jinja-template", "path.jinja"]
50-
51-
Args:
52-
module_name: Module identifier for argv[0] (e.g., "dynamo.vllm")
53-
54-
Returns:
55-
Pytest fixture that mocks sys.argv via monkeypatch
56-
"""
27+
"""Create a pytest fixture for mocking CLI arguments for sglang backend."""
5728

5829
@pytest.fixture
5930
def mock_cli_args(monkeypatch):
60-
"""Mock sys.argv with CLI arguments (explicit or kwargs style)."""
61-
6231
def set_args(*args, **kwargs):
6332
if args:
64-
# Explicit style: pass argv elements directly
6533
argv = [module_name, *args]
6634
else:
67-
# Kwargs style: convert python arg to CLI arg
6835
argv = [module_name]
6936
for param_name, param_value in kwargs.items():
7037
cli_flag = f"--{param_name.replace('_', '-')}"
7138
argv.extend([cli_flag, str(param_value)])
72-
7339
monkeypatch.setattr(sys, "argv", argv)
7440

7541
return set_args

components/src/dynamo/trtllm/tests/conftest.py

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
"""Conftest for dynamo backend unit tests.
5-
6-
Handles conditional test collection to prevent import errors when backend
7-
frameworks are not installed in the current container.
4+
"""Conftest for dynamo.trtllm unit tests only.
5+
Handles conditional test collection to prevent import errors when the tensorrt_llm
6+
framework is not installed in the current container.
87
"""
98

109
import importlib.util
@@ -14,62 +13,29 @@
1413

1514

1615
def pytest_ignore_collect(collection_path, config):
17-
"""Skip collecting backend test files if their framework isn't installed.
18-
19-
Checks test file naming pattern: test_<backend>_*.py
16+
"""Skip collecting trtllm test files if tensorrt_llm module isn't installed.
17+
Checks test file naming pattern: test_trtllm_*.py
2018
"""
2119
filename = collection_path.name
22-
23-
# Map test file prefixes to required modules
24-
backend_requirements = {
25-
"test_vllm_": "vllm",
26-
"test_sglang_": "sglang",
27-
"test_trtllm_": "tensorrt_llm",
28-
}
29-
30-
for prefix, required_module in backend_requirements.items():
31-
if filename.startswith(prefix):
32-
if importlib.util.find_spec(required_module) is None:
33-
return True # Module not available, skip this file
34-
35-
return None # Not a backend test or module available
20+
if filename.startswith("test_trtllm_"):
21+
if importlib.util.find_spec("tensorrt_llm") is None:
22+
return True # tensorrt_llm not available, skip this file
23+
return None
3624

3725

3826
def make_cli_args_fixture(module_name: str):
39-
"""Create a pytest fixture for mocking CLI arguments for a backend.
40-
41-
The returned fixture supports two call styles:
42-
43-
1. Explicit:
44-
mock_vllm_cli("--model", "gpt-2", "--custom-jinja-template", "path.jinja")
45-
46-
2. Kwargs (auto-converts underscores to hyphens):
47-
mock_vllm_cli(model="gpt-2", custom_jinja_template="path.jinja")
48-
49-
Both produce: ["dynamo.vllm", "--model", "gpt-2", "--custom-jinja-template", "path.jinja"]
50-
51-
Args:
52-
module_name: Module identifier for argv[0] (e.g., "dynamo.vllm")
53-
54-
Returns:
55-
Pytest fixture that mocks sys.argv via monkeypatch
56-
"""
27+
"""Create a pytest fixture for mocking CLI arguments for trtllm backend."""
5728

5829
@pytest.fixture
5930
def mock_cli_args(monkeypatch):
60-
"""Mock sys.argv with CLI arguments (explicit or kwargs style)."""
61-
6231
def set_args(*args, **kwargs):
6332
if args:
64-
# Explicit style: pass argv elements directly
6533
argv = [module_name, *args]
6634
else:
67-
# Kwargs style: convert python arg to CLI arg
6835
argv = [module_name]
6936
for param_name, param_value in kwargs.items():
7037
cli_flag = f"--{param_name.replace('_', '-')}"
7138
argv.extend([cli_flag, str(param_value)])
72-
7339
monkeypatch.setattr(sys, "argv", argv)
7440

7541
return set_args

components/src/dynamo/vllm/tests/conftest.py

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
"""Conftest for dynamo backend unit tests.
5-
6-
Handles conditional test collection to prevent import errors when backend
7-
frameworks are not installed in the current container.
4+
"""Conftest for dynamo.vllm unit tests only.
5+
Handles conditional test collection to prevent import errors when the vllm
6+
framework is not installed in the current container.
87
"""
98

109
import importlib.util
@@ -14,62 +13,29 @@
1413

1514

1615
def pytest_ignore_collect(collection_path, config):
17-
"""Skip collecting backend test files if their framework isn't installed.
18-
19-
Checks test file naming pattern: test_<backend>_*.py
16+
"""Skip collecting vllm test files if vllm module isn't installed.
17+
Checks test file naming pattern: test_vllm_*.py
2018
"""
2119
filename = collection_path.name
22-
23-
# Map test file prefixes to required modules
24-
backend_requirements = {
25-
"test_vllm_": "vllm",
26-
"test_sglang_": "sglang",
27-
"test_trtllm_": "tensorrt_llm",
28-
}
29-
30-
for prefix, required_module in backend_requirements.items():
31-
if filename.startswith(prefix):
32-
if importlib.util.find_spec(required_module) is None:
33-
return True # Module not available, skip this file
34-
35-
return None # Not a backend test or module available
20+
if filename.startswith("test_vllm_"):
21+
if importlib.util.find_spec("vllm") is None:
22+
return True # vllm not available, skip this file
23+
return None
3624

3725

3826
def make_cli_args_fixture(module_name: str):
39-
"""Create a pytest fixture for mocking CLI arguments for a backend.
40-
41-
The returned fixture supports two call styles:
42-
43-
1. Explicit:
44-
mock_vllm_cli("--model", "gpt-2", "--custom-jinja-template", "path.jinja")
45-
46-
2. Kwargs (auto-converts underscores to hyphens):
47-
mock_vllm_cli(model="gpt-2", custom_jinja_template="path.jinja")
48-
49-
Both produce: ["dynamo.vllm", "--model", "gpt-2", "--custom-jinja-template", "path.jinja"]
50-
51-
Args:
52-
module_name: Module identifier for argv[0] (e.g., "dynamo.vllm")
53-
54-
Returns:
55-
Pytest fixture that mocks sys.argv via monkeypatch
56-
"""
27+
"""Create a pytest fixture for mocking CLI arguments for vllm backend."""
5728

5829
@pytest.fixture
5930
def mock_cli_args(monkeypatch):
60-
"""Mock sys.argv with CLI arguments (explicit or kwargs style)."""
61-
6231
def set_args(*args, **kwargs):
6332
if args:
64-
# Explicit style: pass argv elements directly
6533
argv = [module_name, *args]
6634
else:
67-
# Kwargs style: convert python arg to CLI arg
6835
argv = [module_name]
6936
for param_name, param_value in kwargs.items():
7037
cli_flag = f"--{param_name.replace('_', '-')}"
7138
argv.extend([cli_flag, str(param_value)])
72-
7339
monkeypatch.setattr(sys, "argv", argv)
7440

7541
return set_args

0 commit comments

Comments
 (0)