Skip to content

Latest commit

 

History

History
116 lines (92 loc) · 2.35 KB

File metadata and controls

116 lines (92 loc) · 2.35 KB

Testing Guide for vLLM Proxy

Setup

  1. Create and activate a Python virtual environment:
python3 -m venv .venv
. .venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
pip install -r test-requirements.txt

Running Tests

Basic Usage

Use the provided test runner script:

./run_tests.sh

Or run manually:

. .venv/bin/activate
PYTHONPATH=src python -m pytest tests/ -v

Environment variables are automatically set by tests/conftest.py.

Advanced Usage with Arguments

Run a specific test file:

./run_tests.sh tests/app/test_openai.py
# Expands to: PYTHONPATH=src python -m pytest tests/ -v tests/app/test_openai.py

Run a specific test function:

./run_tests.sh -k test_signature_default_algo

Run tests with coverage report:

./run_tests.sh --cov=app --cov-report=html

Run tests in quiet mode:

./run_tests.sh -q

Stop on first failure with short traceback:

./run_tests.sh -x --tb=short

Exclude certain tests:

./run_tests.sh -k "not test_quote"

Run tests matching multiple patterns:

./run_tests.sh -k "test_signature or test_stream"

Key Testing Patterns

1. Mocking External Dependencies

# Example from test_helpers.py
def setup_pynvml_mock():
    mock_pynvml = MagicMock()
    mock_pynvml.nvmlInit = MagicMock()
    mock_pynvml.nvmlDeviceGetCount = MagicMock(return_value=1)
    sys.modules['pynvml'] = mock_pynvml

2. Replacing Modules Before Import

# Example from test_openai.py
sys.modules['app.quote.quote'] = __import__('tests.app.mock_quote', fromlist=[''])

3. Mocking Cache Data

# Properly formatted cache data for signature endpoint
cache_data = json.dumps({
    "text": test_data,
    "signature_ecdsa": ecdsa_quote.sign(test_data),
    "signing_address_ecdsa": ecdsa_quote.signing_address,
    "signature_ed25519": ed25519_quote.sign(test_data),
    "signing_address_ed25519": ed25519_quote.signing_address,
})

CI/CD Integration

The test suite is designed to run in CI environments without special hardware:

# Example GitHub Actions workflow
- name: Run tests
  run: |
    python3 -m venv .venv
    . .venv/bin/activate
    pip install -r requirements.txt
    pip install -r test-requirements.txt
    ./run_tests.sh