Skip to main content Switch to mobile version testscope 0.4.0 Run only the tests a change can affect. Built for AI coding agents and CI.
pip install testscope==0.4.0 Copy PIP instructions
Run only the tests your change can affect. Built for AI coding agents and CI.
Coding agents run pytest after every edit. On a 6,000-test suite that is minutes per run. It goes past Claude Code's ~2-minute foreground limit, so the run moves to the background and the agent stops reading its output. testscope records which code and files each test really touches. After that, plain pytest runs only the tests your change can reach.
On a real 6,195-test project, over its last 30 commits:
Method, caveats and raw data: bench/RESULTS.md.
pip install testscope pytest --testscope-record # once (or in CI on main): full run + dependency map # ... edit code ... pytest --testscope # only affected tests When Claude Code runs pytest (it sets CLAUDECODE=1) and a map exists, selection turns on automatically. The agent needs no new command and no hook. For other agents, export TESTSCOPE=on in their environment. TESTSCOPE=off pytest always runs everything. Explicit targets (pytest tests/test_x.py::test_y) are never narrowed.
A git worktree with no map of its own uses the main checkout's map. When a change forces a full run (a config or lockfile changed), testscope records a fresh map during that run, so the next run is narrow again. A run that covers less than 90% of the old map's tests (-k, -x, a subdirectory) keeps the old map. TESTSCOPE_AUTORECORD=off turns this off.
Selected tests run in fail-first order: tests that failed last time, then tests that ran the changed code, then indirect reasons; shorter files first. Whole files move, so module fixtures still run once. TESTSCOPE_ORDER=off keeps pytest's order.
Fingerprints are token-stream hashes without line numbers or comments, so moving code or changing a comment selects nothing. The map is a baseline. Selection compares the working tree with it by content, so it works on uncommitted edits and on branches built from an older main. As you edit, the selection can only grow. Re-record to reset it.
No map yet? (optional AI pick)
TESTSCOPE_AI=claude pytest # your coding agent's own login, no API key pip install 'testscope[ai]' && TESTSCOPE_AI=anthropic pytest # or the API, ANTHROPIC_API_KEY TESTSCOPE_AI= runs auth claude claude -p Claude Code login codex codex exec Codex login (ChatGPT plan) or API key cursor cursor-agent -p Cursor login gemini gemini -p Google login or GEMINI_API_KEY copilot copilot -p Copilot login qwen qwen Qwen Code's own auth opencode opencode run any provider opencode is set up with anthropic Anthropic API ANTHROPIC_API_KEY Each CLI runs read-only in an empty directory, so it sees no project files. TESTSCOPE_AI_MODEL picks the model. Measured: Claude, Codex and opencode. Cursor, Gemini, Copilot and Qwen are tested against their documented output only.
Until a map is recorded, a model reads the diff and a test index and picks the test files to run. On the same faults it caught 33 of 34 while it ran about 3 files, for about 1 cent a call on Opus 5.5 (0.05 cents on Haiku 5.5). It is a guess: it found every failing file only 21 times in 34. Once a map exists the AI step is off. (We measured it on top of the map too: it caught nothing extra, so that mode was removed.) Details: bench/RESULTS.md.
examples/github-actions.yml:
push to main: pytest --testscope-record; the map goes into the Actions cache.
pull requests: restore the newest map; pytest --testscope.
merge queue + nightly: plain full run. This is the safety net for what any selector can miss.
Recording needs Python 3.12+ (sys.monitoring). Selection works on any 3.9+.
A test that starts a child process with a scrubbed environment (env={}), or with python -I / -E, hides that child's deps. Shell scripts that read files themselves are seen only as "script ran".
Network services, databases and time are not dependencies. A flaky test stays flaky.
Package tracking sees Python code that runs inside a package. A package that is only a compiled extension, with no Python layer, is invisible; a lockfile or requirements*.txt edit still triggers a full run.
A module-level edit runs at most 5 "import canary" tests for crashes at import time.
eval/exec strings and other dynamic code that no recorded test reached cannot be mapped.
bench/RESULTS.md: real commits and fault injection on one 6,195-test project. For each injected fault, a full-suite run gives the ground truth. Missed files are rerun to rule out flaky tests. The harness is in bench/, so you can run it on your own suite.
Apache-2.0 View SPDX License List
ai agents ci claude code pytest regression test selection test impact analysis
Programming Language Python :: 3
Topic Software Development :: Testing
Release files for testscope 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 240.1 kB
Release files / testscope-0.4.0.tar.gz
Release files / testscope-0.4.0-py3-none-any.whl
Security for testscope 0.4.0
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.
Release history Release notifications | RSS feed
Nov 18, 2026 2 release files No provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation




