pytest-optimizer
/pytest-optimizer
Przyspiesza wolne testy i fixtures pytest przez zmierzoną optymalizację z zabezpieczeniami.
Ocena i bezpieczeństwo
- Pliki w paczce
- 16
- Skrypty
- 4
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 25.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
- 4 skrypty w paczce. Przejrzyj je przed instalacją, bo Claude może je uruchomić.
Skrypty: references/isolate.py, references/measure.py, templates/conftest_cache_snippet.py, templates/pytest_optimizer_plugin.py
Co robi i kiedy
Przyspiesza wolne testy i fixtures pytest przez zmierzoną optymalizację z zabezpieczeniami.
Oryginalny opis (EN)
Use when pytest tests or fixtures are slow and you want them faster: speed up the suite with measured, safety-gated optimization.
Jak działa
- The loop
- Step 1: Read-only preflight
- Orchestration Plan
- Step 2: Run the phases
- Step 3: Report and decide whether to loop again
- Opt-in scaffolds
- Graceful degradation
- References
- Portability notes
Podgląd SKILL.md
---
name: pytest-optimizer
description: >-
Use when pytest tests or fixtures are slow and you want them faster: speed
up the suite with measured, safety-gated optimization.
allowed-tools: ["Bash", "Read", "Grep", "Glob", "Write", "Edit", "AskUserQuestion"]
metadata:
argument-hint: "[test-path-or-marker] [--phase=scan|benchmark|plan|execute] [--force] [--hygiene] [--memory-dir=<path>]"
source: "plugins/pytest-optimizer/skills/pytest-optimizer/SKILL.md"
---
# pytest-optimizer
Profile a pytest suite, find safe speedups, and apply each as its own verified
commit on a new branch, through a resumable, idempotent four-phase loop.
Measure before you mutate, and prove a speedup against the project's own timing
noise before you trust it. A change whose measured saving falls inside the noise
band, whose run exits non-zero, or whose collected tests change is never
committed, except a deselection the user approved with its test count, which is
reported as a smaller default run, not a faster suite.
`$ARGUMENTS` may name a test path or marker to scope the run, a `--phase` to jump
to, `--force` to ignore idempotency tokens and re-run, `--hygiene` to add the opt-in typing
and parametrize detectors, and `--memory-dir` to
override where durable state is written.
Paths under `../../scripts/` resolve from this skill's directory: print the absolute path once and write it literally in each command, since shell variables do not persist between Bash calls.
## The loop
```
00-scan -> 01-benchmark -> 02-plan -> 03-execute -> (re-scan)
```
Each phase reads and writes durable JSON under the resolved memory directory;
re-running resumes at the first phase whose `completed` flag is false, which
`measure.py state resume` reports. After `03-execute`, re-scan and loop until no
candidate clears the rubric.
The phase skills set `disable-model-invocation`, so this skill cannot invoke
them. To run a phase, read its file and follow it:
- the `pytest-optimizer-00-scan` skill reads `AGENTS.md`/`CLAUDE.md` and prior `state.json`;
writes `baseline.json`, `capabilities.json`, `collection.txt`,
`hypotheses.json`.
- the `pytest-optimizer-01-benchmark` skill reads `baseline.json`, `hypotheses.json`; writes
`benchmarks.json`, `control.json` and one hash-bound patch per candidate.
- the `pytest-optimizer-02-plan` skill reads `benchmarks.json`, `baseline.json`; writes
`plan.json`.
- the `pytest-optimizer-03-execute` skill reads `plan.json`, `baseline.json`, `control.json`;
writes `execution-log.json` and commits on a new branch in a scratch
worktree, leaving the user's checkout, index and branches untouched.
## Step 1: Read-only preflight
Write no project files here; `00-scan` owns capability probing and creating the
memory directory. The runner may update its own environment (below).
1. Read the project's own test and quality-check commands from `AGENTS.md`,
`CLAUDE.md`, `justfile`, `tox.ini`, and `pyproject.toml`; the runner
(`pytest`, `uv run`, `tox`, `nox`, `hatch`) is the project's choice.
2. Resolve the memory directory by the lookup order in
`references/memory-schema.md`. If one exists, take the resume point
from `measure.py state resume <memory-dir>/state.json`.
3. Read the installed pytest version, for the plan only, through the project's
runner so the project environment answers, not the system Python (a runner
such as `uv run` may sync its environment first; `uv run --help` lists
`--no-sync` to avoid it):
```console
$ pytest --version
```
Prefix the project's runner when it has one (`uv run pytest --version`,
`tox -e py -- --version`).
If there is no pytest suite, or pytest cannot start for the project's command,
stop with the halted-run shape in `references/output-contract.md`, naming
that one cause. A saving is a measured number: when nothing was run, state no
projected timing, and call a scope change a hypothesis to benchmark, not a fix.
A phase whose input is missing stops the same way.
## Orchestration Plan
Before any measurement or edit, present a plan and get approval.
Enter plan mode before the first edit. In Claude Code call `EnterPlanMode`; in Cursor, Codex, or Gemini use `/plan` or `Shift+Tab`. Where plan mode is unavailable, present the plan as text.
Present a plan stating:
- the resolved test and quality-check commands (Step 1);
- the pytest version, and that `00-scan` will probe plugins and gate
capabilities;
- the resolved memory directory, or that `00-scan` will create it;
- the starting phase (fresh `00-scan`, or resume) and the scope (`$ARGUMENTS`
path or marker, or the whole suite);
- whether the opt-in typing detectors (`--hygiene`) are on;
- that suite edits happen only in `03-execute`, inside a scratch worktree on a
new branch, one commit per speedup, each applied from its measured patch and
verified green with the same collected tests; your checkout is not touched and
you merge the branch yourself.
Let the user narrow scope, exclude risky heuristics, or cap the commit count.
Wait for approval, then exit plan mode before running any phase. Without plan
mode, the phase structure still forces analysis before any write; without an
interactive session, stop after presenting the plan.
## Step 2: Run the phases
Read and follow each phase file in order, honoring `--phase` and resume state.
Pass along the test command and memory directory. `00-scan`, `01-benchmark`, and
`02-plan` never edit the user's working tree. Stop for the user's decision at
each phase's panel.
## Step 3: Report and decide whether to loop again
After `03-execute`, present the result per `references/output-contract.md`
and write it per `references/prose-rules.md`, then offer a re-scan, the
opt-in scaffolds, or stop. The contract's closing sentence (the merge command)
comes first and carries no note on pushing or on what remains to speed up.
Without an interactive question tool, follow the contract's next-step rule.
## Opt-in scaffolds
When profiling shows it would help, offer (never impose) a project-owned helper:
- A timing plugin (`templates/pytest_optimizer_plugin.py`) that wraps
`pytest_fixture_setup` to attribute setup cost to the individual fixture, which
pytest core cannot do. It loads from the rootdir `conftest.py` only.
- A `config.cache` memoization snippet (`templates/conftest_cache_snippet.py`)
with an invalidation token and an xdist write-guard, for expensive build
artifacts recomputed every run. It raises until `INPUTS` is set.
Generate only on explicit confirmation. The output is untracked; exclude it per
the memory-schema reference unless the user chooses to commit it.
## Graceful degradation
- **Old pytest:** gate features via the version matrix; widen `k` when duration
precision is coarser (pytest before 6.0 used `time.time()`).
- **No xdist, randomly, or deadfixtures:** fall back to serial runs, manual
reversed-order isolation checks, and the built-in `--fixtures` vs
`--fixtures-per-test` diff.
- **Dirty working tree:** the rule is in `references/memory-schema.md`
("Idempotency token"). `03-execute` works in its own worktree and does not
care about edits made after the scan.
## References
- `references/scoring-rubric.md`: weighted rubric and the hard safety gate.
- `references/heuristic-catalog.md`: heuristic ids with
detect/action/risk/effort.
- `references/version-matrix.md`: feature, min version, probe, fallback.
- `references/memory-schema.md`: memory location, file shapes, idempotency
token, baseline-diff rule.
- `references/durations-parsing.md`: invoking and parsing `--durations`,
phase bucketing, JUnit XML, the noise band.
- `references/measure.py`: timing and noise arithmetic, outcome and node-id
gates, and the phase files' state, baseline and benchmark records
(`measure.py --help`).
- `references/isolate.py`: input digest, staleness check, owned scratch
worktrees, bound patches, the commit gate (`isolate.py --help`).
- `references/fixture-analysis.md`: scope model and the
unused/duplicate/mis-scope recipes.
- `references/safety-gates.md`: order independence, collection determinism,
xdist preconditions.
- `references/parametrize-convention.md`: the typed NamedTuple + test_id
convention and typed builtins.
- `references/output-contract.md`: the shared output shape.
## Portability notes
- `$ARGUMENTS` — the text the user passed when invoking this skill. If your host does not substitute it, read it as the user's request in the current turn, and ask when there is none.
- Bundled files — every relative path in this skill points at a file shipped inside this skill directory. Read them from here, not from the host's plugin tree.
Pliki w paczce (16)
- SKILL.md 9 KB
- agents/openai.yaml 1 KB
- references/durations-parsing.md 6 KB
- references/fixture-analysis.md 6 KB
- references/heuristic-catalog.md 15 KB
- references/isolate.py 24 KB
- references/measure.py 65 KB
- references/memory-schema.md 14 KB
- references/output-contract.md 8 KB
- references/parametrize-convention.md 4 KB
- references/prose-rules.md 5 KB
- references/safety-gates.md 5 KB
- references/scoring-rubric.md 5 KB
- references/version-matrix.md 7 KB
- templates/conftest_cache_snippet.py 3 KB
- templates/pytest_optimizer_plugin.py 3 KB
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · tony/skills | 100 | MIT |
| tony/skills | 100 | MIT |
Migawka bazy z 13.11.2026 · wersja paczki 3d3eabfa4d8d (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100pytest-optimizer-00-scan
Rozpoczyna lub odnawia punkt odniesienia optymalizacji pytest przez profilowanie testów i fixtures bez edycji zestawu testów. - 100pytest
Pomaga pisać testy w Pytest i uruchamiać je w CI/CD: fixtures, parametryzacja, markery i wtyczki. - 100python-testing
Wspiera testowanie w Python z pytest: pokrycie kodu, fixtures i mockowanie. - 100pytest-runner
Uruchamia testy Python w pytest z fixtures, markerami, pokryciem kodu i wykonywaniem równoległym. - 100python-testing
Pisze i uruchamia testy Python w pytest z fixtures, mockowaniem, pokryciem kodu i wzorcem AAA oraz konfiguruje pytest. - 100pytest-fixtures
Opisuje fixtures pytest, pliki conftest, dekoratory parametrize i zakresy fixtures przy przygotowaniu środowiska testów.