Speed up local parametric testing capabilities by 2-5x#6256
Speed up local parametric testing capabilities by 2-5x#6256
Conversation
…rary builds and reuse containers. Introduce new rules for parametric testing in documentation. Update related scripts and fixtures for improved performance during test runs.
|
|
|
✨ Fix all issues with BitsAI or with Cursor
|
nccatoni
left a comment
There was a problem hiding this comment.
These changes could cause reliability issues. While it might be fine to speedup local development you should make sure that all parametric tests do indeed pass. You should also get a review from @cbeauchesne (OOO this week)
docs/scenarios/parametric.md
Outdated
|
|
||
| ### Making parametric runs faster | ||
|
|
||
| - **Skip the build when the image already exists:** Use `--skip-parametric-build` (or set `SKIP_PARAMETRIC_BUILD=1`) when you are only changing test code. This avoids rebuilding the parametric library image on every run. When you change the Dockerfile or app code under `utils/build/docker/<lang>/parametric/`, run without this option so the image is rebuilt. |
There was a problem hiding this comment.
Are you sure that docker doesn't already cache the images in this case ?
There was a problem hiding this comment.
Going based on empirical evidence, it saved an additional ~1-2 seconds per run since we avoid the layer cache validation
tests/parametric/conftest.py
Outdated
| ) -> Generator[TestAgentAPI, None, None]: | ||
| session_agent = request.getfixturevalue("_session_test_agent") | ||
| if worker_id == "master" and not agent_env and session_agent is not None: | ||
| yield session_agent |
There was a problem hiding this comment.
I'm not sure to get how this works, what if agent_env/otlp ports change from one test to another, it won't be applied on session_agent, right ?
cbeauchesne
left a comment
There was a problem hiding this comment.
If I understand correctly, this option is only meant for local dev.
I usually strongly recommand to use nodeid among run.sh when running on local on parametric tests, it allows to run only the subset of test. I'm wondering what is the benefit of this change using this setup ?
|
@cbeauchesne Great question — I ran benchmarks to compare the two approaches on Single test re-run (the targeted use case)
~1.8x faster for a single test re-run. The savings come from:
Running a whole file (e.g. test_tracer.py, ~14 tests)
For a whole file, nodeid-only is ~3.5x faster because xdist runs tests in parallel. The PR approach runs tests sequentially and the container reuse causes test failures via state pollution. SummaryYou're right that nodeid already narrows the test subset — and for running multiple tests, nodeid-only is both faster and more reliable. The benefit of The docs in this PR try to call this out (the "single-worker runs may cause failures" warning), but I agree the use case is narrower than I initially presented. Happy to adjust the recommendation to be more explicit that |
Based on benchmark data: nodeid alone is faster for multi-test runs (~20s vs ~70s) due to xdist parallelism. +1 --skip-parametric-build is ~1.8x faster only for single-test repeated re-runs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
We try to keep
To me, that's a blocker (I think it's related to my point here). The full point of parametric test is to have different parameters for a single tests, so that's by design the main use case of this scenario. WDYT of just keeping the "no rebuild" feature, since it'll be the main benefit for the local dev using one nodeid ? |
The single-worker container reuse caused test pollution failures when running multiple tests, which is the primary use case for parametric tests. The +1 flag also diverged from the pytest CLI convention (run.sh should stay close to bare pytest, so -n <int> is the right form). Keep only --skip-parametric-build (and SKIP_PARAMETRIC_BUILD=1), which skips rebuilding the library image on each invocation and saves ~3-4s per run with no correctness risk. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Works for me! Just made the edits so it only does no rebuild |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Consolidate env-var-to-option defaulting in pytest_configure alongside similar logic for other options, instead of inline in parametric.py. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Motivation
Iterating on parametric tests locally is slow because
run.shrebuilds the library Docker image on every invocation, even when nothing has changed. This is wasted time when only the test code is changing.Changes
Adds
--skip-parametric-build(andSKIP_PARAMETRIC_BUILD=1) torun.sh: when the flag is set and the library image already exists, the build step is skipped (~3–4s saved per run).What was dropped from the earlier version of this PR:
The original PR also added a
+1flag that forced a single xdist worker and enabled library container reuse between tests. Per reviewer feedback, this was a blocker:run.shaims to stay close to barepytest; the right way to set worker count is-n <int>(standard pytest CLI), not a custom+1shorthand.library_envparameters — sequential container reuse causes test pollution failures, which is the primary use case for this scenario.The
--skip-parametric-buildflag is the main benefit for local dev iteration and carries no correctness risk.Example:
# Edit test code, then re-run quickly without rebuilding the image TEST_LIBRARY=nodejs ./run.sh PARAMETRIC --skip-parametric-build tests/parametric/test_tracer.pyWorkflow
🚀 Once your PR is reviewed and the CI green, you can merge it!
🛟 #apm-shared-testing 🛟
Reviewer checklist
tests/ormanifests/is modified ? I have the approval from R&P teambuild-XXX-imagelabel is present