4e4bf84b87
Merge https://github.com/google/adk-python/pull/6098 ## Summary Two changes that reduce unit-test runtime without losing coverage: 1. **Enable `pytest-xdist` in CI** (`-n auto`). The ~7,300-test suite was running single-threaded even though `pytest-xdist` is already a declared dev dependency. 2. **Remove dead `llm_backend` parametrize** from 26 tests, which were running twice over identical code paths. ## Impact | | Before | After | |---|---|---| | Wall-clock (full suite, local 12-core) | **121s** (71% CPU, single-core bound) | **72s** (622% CPU) → **~40% faster** | | Executions from dead param | +26 redundant | 0 | CI runners benefit proportionally to their core count; the parallelism win is the dominant factor. ## Why the `llm_backend` removal is safe The `@pytest.mark.parametrize("llm_backend", ["GOOGLE_AI", "VERTEX"])` decorator on these 26 tests (24 in `test_instructions.py`, 2 in `test_llm_request.py`) did **nothing**: - No test body referenced `llm_backend`. - No fixture consumed it (the working pattern is the `env_variables` fixture in `conftest.py`, a different name that actually sets `GOOGLE_GENAI_USE_ENTERPRISE`). - Both param values executed identical code under the same ambient env. I scanned every backend-branching site in the source and confirmed the full call surface of these tests has **zero backend branching**: - `flows/llm_flows/instructions.py` and `contents.py` — no variant checks. - `models/llm_request.py::append_instructions` — pure data transform. Real dual-backend FD-prep coverage (the env-driven path through `base_tool._get_declaration` → `_automatic_function_calling_util` / `_gemini_schema_util`) remains intact in `test_agent_tool.py`, which correctly uses the `env_variables` fixture to flip the variant. ## Test plan - [x] `test_instructions.py` + `test_llm_request.py`: 60 passed (was 86 with duplicates; 26 redundant executions removed, all unique cases preserved). - [x] Full suite under `-n auto`: 7160 passed, 0 new failures. - [x] pyink + isort clean; pre-commit hooks pass. > Note: `telemetry/test_functional.py::test_instrumented_with_opentelemetry_instrumentation_google_genai` fails locally in isolation on a clean `main` too (local env / optional `opentelemetry-instrumentation-google-genai`); pre-existing and unrelated to this PR. Co-authored-by: Wei Sun (Jack) <weisun@google.com> COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/6098 from google:perf/reduce-unittest-runtime 0baac8fb8642433bab779ea8cb20779431e25713 PiperOrigin-RevId: 931335891
45 lines
1.0 KiB
YAML
45 lines
1.0 KiB
YAML
name: Python Unit Tests
|
|
|
|
on:
|
|
push:
|
|
branches: [main, v1, v2]
|
|
pull_request:
|
|
branches: [main, v1, v2]
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
strategy:
|
|
matrix:
|
|
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Set up Python ${{ matrix.python-version }}
|
|
uses: actions/setup-python@v6
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
|
|
- name: Install the latest version of uv
|
|
uses: astral-sh/setup-uv@v7
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
uv venv .venv
|
|
source .venv/bin/activate
|
|
uv sync --extra test
|
|
|
|
- name: Run unit tests with pytest
|
|
run: |
|
|
source .venv/bin/activate
|
|
pytest tests/unittests \
|
|
-n auto \
|
|
--ignore=tests/unittests/artifacts/test_artifact_service.py \
|
|
--ignore=tests/unittests/tools/google_api_tool/test_googleapi_to_openapi_converter.py
|