Repository navigation
Prefer for loops over parametrized tests in AGENTS.md - #4150
kevinjqliu wants to merge 1 commit into
Conversation
Each parametrized case adds per-item pytest overhead (~0.3ms measured), which slows the suite as cases accumulate. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
I noticed that a lot of new PRs tend to use Hopefully this nudge all the agents to do the right thing |
There was a problem hiding this comment.
🟢 Approval recommended
The documentation-only change matches the stated intent and has no unresolved review findings.
No open issues 🎉
What changed in this PR
This documentation-only PR updates contributor testing guidance to reduce pytest overhead without changing runtime behavior.
Changes:
- Prefer loops within a single test over parametrization.
- Require input values in assertion messages to identify failing cases.
- Reserve parametrization for cases needing different fixtures.
| File | Description |
|---|---|
| AGENTS.md | Adds guidance on loops, assertion messages, and when to use parametrization. |
Review effort: Balanced
|
Can we add something about using multiple tests if the parameters are sufficiently complicated? I've seen a number of tests that parameterize on 3-4+ very complicated fixtures. Even a for loop makes reading them a mess. The loss in readability doesn't make up for the few lines of code savings. |
Rationale for this change
Adds an
AGENTS.mdtesting guideline to prefer aforloop in a single test over@pytest.mark.parametrize. Each parametrized case is a separate pytest item with its own collection, setup, and reporting overhead, which adds up across the suite.Measured locally with the project's
tests/conftest.py(pytest -m unit -q, trivial bucket-transform assertion as the test body):parametrizeforloopRoughly 0.3ms of overhead per case. About 2,258 of the 4,022 collected unit tests (56%) are parametrized cases.
Are these changes tested?
Documentation-only change.
prekhooks (markdownlint, codespell, end-of-file, trailing whitespace) passed on commit.Are there any user-facing changes?
No.