[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

View File

@@ -191,10 +191,10 @@ jobs:
- name: Run Python unit tests
run: |
cd sgl-model-gateway
cd sgl-model-gateway/bindings/python
source "$HOME/.cargo/env"
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
run: |

View File

@@ -29,7 +29,7 @@ jobs:
- name: Build and Push
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}
docker buildx build . -f docker/gateway.Dockerfile \

View File

@@ -6,16 +6,22 @@ This directory contains the Python bindings for the SGLang Router, built using [
```
bindings/python/
├── src/ # Rust source code for Python bindings
── lib.rs # PyO3 bindings implementation
── sglang_router/ # Python source code
│ ├── __init__.py
│ ├── version.py
│ ├── launch_server.py
│ ├── launch_router.py
│ ├── router.py
│ ├── router_args.py
│ └── mini_lb.py
├── src/ # Source code (src layout)
── lib.rs # Rust/PyO3 bindings implementation
│ └── sglang_router/ # Python source code
├── __init__.py
├── version.py
├── launch_server.py
├── launch_router.py
├── router.py
├── router_args.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
├── pyproject.toml # Python package configuration
├── setup.py # Setup configuration
@@ -51,15 +57,15 @@ pip install dist/sglang_router-*.whl
## Testing
```bash
# Run Python tests
cd sgl-model-gateway
pytest py_test/
# Run Python unit tests (after maturin develop)
cd sgl-model-gateway/bindings/python
pytest tests/
```
## 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
## Notes

View File

@@ -39,6 +39,7 @@ dependencies = [
[project.optional-dependencies]
dev = [
"requests>=2.25.0",
"pytest>=7.0.0",
]
[project.scripts]
@@ -48,7 +49,16 @@ sglang-router = "sglang_router.cli:main"
[tool.maturin]
python-source = "."
python-source = "src"
module-name = "sglang_router.sglang_router_rs"
# Exclude bindings/python/README.md to use root README only
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)",
]

View File

@@ -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)"
)