|
| 1 | +# SPDX-License-Identifier: Apache-2.0 |
| 2 | +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | + |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | + |
| 7 | +def pytest_addoption(parser): |
| 8 | + """Add custom command line options.""" |
| 9 | + parser.addoption("--config-list-file", |
| 10 | + default="configs/models-small.txt", |
| 11 | + help="File containing list of config files to test") |
| 12 | + parser.addoption("--tp-size", |
| 13 | + default=1, |
| 14 | + type=int, |
| 15 | + help="Tensor parallel size") |
| 16 | + |
| 17 | + |
| 18 | +def pytest_generate_tests(metafunc): |
| 19 | + """Generate test parameters from config files.""" |
| 20 | + if "config_filename" in metafunc.fixturenames: |
| 21 | + config_list_file = metafunc.config.getoption("--config-list-file") |
| 22 | + tp_size = metafunc.config.getoption("--tp-size") |
| 23 | + |
| 24 | + # Handle both relative and absolute paths |
| 25 | + config_list_path = Path(config_list_file) |
| 26 | + if not config_list_path.is_absolute(): |
| 27 | + # If relative, try relative to test directory first |
| 28 | + test_dir_path = Path(__file__).parent / config_list_file |
| 29 | + if test_dir_path.exists(): |
| 30 | + config_list_path = test_dir_path |
| 31 | + else: |
| 32 | + # Try relative to current working directory |
| 33 | + config_list_path = Path.cwd() / config_list_file |
| 34 | + |
| 35 | + print(f"Looking for config list at: {config_list_path}") |
| 36 | + |
| 37 | + config_files = [] |
| 38 | + if config_list_path.exists(): |
| 39 | + # Determine config directory (same directory as the list file) |
| 40 | + config_dir = config_list_path.parent |
| 41 | + |
| 42 | + with open(config_list_path) as f: |
| 43 | + for line in f: |
| 44 | + line = line.strip() |
| 45 | + if line and not line.startswith("#"): |
| 46 | + config_path = config_dir / line |
| 47 | + print(f"Checking config file: {config_path}") |
| 48 | + if config_path.exists(): |
| 49 | + config_files.append(config_path) |
| 50 | + print(f" ✓ Found: {config_path}") |
| 51 | + else: |
| 52 | + print(f" ✗ Missing: {config_path}") |
| 53 | + else: |
| 54 | + print(f"Config list file not found: {config_list_path}") |
| 55 | + |
| 56 | + # Generate test parameters |
| 57 | + if config_files: |
| 58 | + metafunc.parametrize(["config_filename", "tp_size"], |
| 59 | + [(config_file, int(tp_size)) |
| 60 | + for config_file in config_files], |
| 61 | + ids=[ |
| 62 | + f"{config_file.stem}-tp{tp_size}" |
| 63 | + for config_file in config_files |
| 64 | + ]) |
| 65 | + else: |
| 66 | + print("No config files found, test will be skipped") |
0 commit comments