[model-gateway]: move unit tests to bindings/python/tests/ (#16430)

This commit is contained in:
Simo Lin
2026-01-04 18:10:35 -08:00
committed by GitHub
parent f8411ded6e
commit 0ff3747ca1
18 changed files with 48 additions and 18 deletions
+2 -2
View File
@@ -191,10 +191,10 @@ jobs:
- name: Run Python unit tests - name: Run Python unit tests
run: | run: |
cd sgl-model-gateway cd sgl-model-gateway/bindings/python
source "$HOME/.cargo/env" source "$HOME/.cargo/env"
python3 -m pip install pytest pytest-cov pytest-xdist python3 -m pip install pytest pytest-cov pytest-xdist
pytest -q py_test/unit --cov=sglang_router --cov-config=bindings/python/.coveragerc --cov-report=term-missing --cov-fail-under=80 pytest -q tests --cov=sglang_router --cov-config=.coveragerc --cov-report=term-missing --cov-fail-under=80
- name: Run Python integration tests - name: Run Python integration tests
run: | run: |
+1 -1
View File
@@ -29,7 +29,7 @@ jobs:
- name: Build and Push - name: Build and Push
run: | run: |
version=$(cat sgl-model-gateway/bindings/python/sglang_router/version.py | cut -d'"' -f2) version=$(cat sgl-model-gateway/bindings/python/src/sglang_router/version.py | cut -d'"' -f2)
tag=v${version} tag=v${version}
docker buildx build . -f docker/gateway.Dockerfile \ docker buildx build . -f docker/gateway.Dockerfile \
+13 -7
View File
@@ -6,9 +6,9 @@ This directory contains the Python bindings for the SGLang Router, built using [
``` ```
bindings/python/ bindings/python/
├── src/ # Rust source code for Python bindings ├── src/ # Source code (src layout)
│ └── lib.rs # PyO3 bindings implementation │ ├── lib.rs # Rust/PyO3 bindings implementation
├── sglang_router/ # Python source code │ └── sglang_router/ # Python source code
│ ├── __init__.py │ ├── __init__.py
│ ├── version.py │ ├── version.py
│ ├── launch_server.py │ ├── launch_server.py
@@ -16,6 +16,12 @@ bindings/python/
│ ├── router.py │ ├── router.py
│ ├── router_args.py │ ├── router_args.py
│ └── mini_lb.py │ └── mini_lb.py
├── tests/ # Python unit tests
│ ├── conftest.py
│ ├── test_validation.py
│ ├── test_arg_parser.py
│ ├── test_router_config.py
│ └── test_startup_sequence.py
├── Cargo.toml # Rust package configuration for bindings ├── Cargo.toml # Rust package configuration for bindings
├── pyproject.toml # Python package configuration ├── pyproject.toml # Python package configuration
├── setup.py # Setup configuration ├── setup.py # Setup configuration
@@ -51,15 +57,15 @@ pip install dist/sglang_router-*.whl
## Testing ## Testing
```bash ```bash
# Run Python tests # Run Python unit tests (after maturin develop)
cd sgl-model-gateway cd sgl-model-gateway/bindings/python
pytest py_test/ pytest tests/
``` ```
## Configuration ## Configuration
- **pyproject.toml**: Defines package metadata, dependencies, and build configuration - **pyproject.toml**: Defines package metadata, dependencies, and build configuration
- **python-source**: Set to "." to indicate Python source is in the same directory as pyproject.toml - **python-source**: Set to `"src"` indicating Python source uses the src layout
- **module-name**: `sglang_router.sglang_router_rs` - the Rust extension module name - **module-name**: `sglang_router.sglang_router_rs` - the Rust extension module name
## Notes ## Notes
@@ -39,6 +39,7 @@ dependencies = [
[project.optional-dependencies] [project.optional-dependencies]
dev = [ dev = [
"requests>=2.25.0", "requests>=2.25.0",
"pytest>=7.0.0",
] ]
[project.scripts] [project.scripts]
@@ -48,7 +49,16 @@ sglang-router = "sglang_router.cli:main"
[tool.maturin] [tool.maturin]
python-source = "." python-source = "src"
module-name = "sglang_router.sglang_router_rs" module-name = "sglang_router.sglang_router_rs"
# Exclude bindings/python/README.md to use root README only # Exclude bindings/python/README.md to use root README only
exclude = ["README.md"] exclude = ["README.md"]
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
markers = [
"unit: mark test as a unit test (no GPU required)",
]
@@ -0,0 +1,14 @@
"""
Pytest configuration for sglang_router Python binding tests.
These are unit tests that run without GPU resources or external dependencies.
"""
import pytest
def pytest_configure(config):
"""Configure pytest markers."""
config.addinivalue_line(
"markers", "unit: mark test as a unit test (no GPU required)"
)