pytest-selective
Change one Python function and run the tests that depend on it. pytest-selective follows the change through your code, so you can catch a regression in a caller without waiting for the whole suite.
Free and open source under Apache 2.0. Use it locally with your existing pytest suite or add it to CI.
Try it on your next edit
In a project with a passing pytest suite, install the plugin:
uv add --dev pytest-selective
Commit the dependency and lockfile changes. Edit an application function, then run:
uv run pytest --selective
Read the selection summary to see which files your edit affected. The selector follows indirect imports too. If scope is uncertain, it runs the full suite. Use uv run pytest --no-selective for a full comparison.
In CI you can move selection ahead of collection and service startup. A documentation edit can then skip a database job before you pay to start its runner.
Add it to CI with one prompt
Paste this into your coding agent from the root of your repository:
Set up pytest-selective in this repository. Fetch https://pytest-selective.readthedocs.io/en/latest/agent-setup.md and follow it.
Your agent opens a pull request with the workflow changes and measurements. You can review which checks ran, how long you waited, and how much runner time they used.
Quickstart · Adoption guide · GitHub Actions reference
Follow a change through CI
Suppose you change how round_discount() rounds a price. A checkout test calls that function through the order service, so the selector includes it. A profile test with no dependency on pricing can sit this run out. If a shared pytest fixture changes, the selection can expand to the full suite.
How much time could you save?
Change a MongoDB test and keep the database checks that matter. In pytest-obligation, that edit passed CI in 54 seconds instead of 5m22s, using 93 runner-seconds instead of 1,602. Explore the measured examples.
Declare runtime dependencies · Add caching, evidence reuse and balanced shards with CI-esta · Contribute · License
Go deeper
- Run locally
- Declare runtime inputs
- Skip unrelated CI jobs
- Understand a full-suite fallback
- Check the guarantees
Detailed adoption reference — installation options, selection guarantees, benchmarks and tool comparisons.
Project quality checks
| Contract | Cases passed | Planted bugs caught | |
|---|---|---|---|
| ✅ | selection test_selection_contract.py::test_selection49 histories (25 witnesses, 24 samples, seed 11) · every action covered · Quint 0.33.1 |
64/64 | 14/14 |
Bugs this contract found
- A test that does
from pkg import *was not selected when a submodule pkg lists in all changed. Fixed in #94 · found by the runtime check (pytest loaded the changed file, the planner skipped the test), after an adversarial review reported it; witness starImportFollowsAllTest · regression testtests/testing/test_impact_graph.py::test_star_import_reaches_the_submodules_its_package_lists_in_all. 1 of 49 histories diverge when planted bugstar-exports-ignored(Reintroduces the star-import bug: from pkg import * no longer reaches the submodules pkg lists in all) reintroduces it; first caught bywitness-starImportFollowsAllTestat state 2, afteredit(file='alpha', target=''). - Editing a plugin loaded by
addopts = -p NAMEselected no test, though it is loaded into every session. Fixed in #95 · found by the runtime check (pytest loaded the changed file, the planner skipped the test), after an adversarial review reported it; witness commandLinePluginSelectsEveryTestTest and random histories · regression testtests/testing/test_impact_graph.py::test_command_line_plugin_in_addopts_reaches_every_test. 2 of 49 histories diverge when planted bugaddopts-plugins-ignored(Reintroduces the plugin bug: a plugin named by -p in addopts is no longer a dependency of every test) reintroduces it; first caught bywitness-commandLinePluginSelectsEveryTestTestat state 1, afteredit(file='plugin', target=''). - A bare
import helpersresolved by pytest's default import mode was not followed, so editing tests/helpers.py selected nothing. Fixed in #96 · found by the runtime check (pytest loaded the changed file, the planner skipped the test), after an adversarial review reported it; witness bareTestImportFollowsPrependModeTest · regression testtests/testing/test_impact_graph.py::test_bare_import_resolves_from_the_importers_prepend_mode_base_directory. 1 of 49 histories diverge when planted bugprepend-roots-ignored(Reintroduces the import-mode bug: imports no longer resolve from the directories pytest prepends to sys.path) reintroduces it; first caught bywitness-bareTestImportFollowsPrependModeTestat state 2, afteredit(file='helper', target=''). - A test that read a tracked file with open() and a literal path was not selected when that file changed. Fixed in #106 · found by the runtime check (pytest opened the changed file, the planner skipped the test), after an adversarial review reported it; witness literalPathReadTest · regression test
tests/testing/test_impact_graph.py::test_reading_a_tracked_file_by_literal_path_selects_the_reader. 1 of 49 histories diverge when planted bugliteral-reads-ignored(Reintroduces the literal-read bug: open('data/table.json') no longer makes the reader depend on that file) reintroduces it; first caught bywitness-literalPathReadTestat state 2, afteredit(file='table', target='').
Planted bugs this contract catches
head-edges-only: Plans with the head tree's edges only, so a deleted module's former importers are not selected. Caught bywitness-deletedModuleSelectsFormerImportersTestat state 1, afterremove(file='beta', target='').direct-importers-only: Follows only files that import a changed file directly, not their importers. Caught bywitness-transitiveEditTestat state 1, afteredit(file='beta', target='').global-inputs-ignored: Treats requirements.txt like any unreferenced file instead of selecting every test. Caught bywitness-globalInputSelectsEveryTestTestat state 1, aftertouchGlobal(file='', target='').content-follows-imports: Reads a kind: content declaration as an import, so it also follows the read file's imports. Caught bywitness-contentReadIsNotTransitiveTestat state 2, afteredit(file='beta', target='').conftest-scope-collapsed: Scopes every conftest to the top test directory, so tests/sub/conftest.py reaches every test. Caught bywitness-nestedConftestSelectsItsSubtreeTestat state 1, afteredit(file='subconftest', target='').parse-errors-ignored: Treats an unparseable file as importing nothing instead of stopping with an error. Caught bywitness-unparseableSourceIsAnErrorTestat state 1, afterbreakSyntax(file='beta', target='').assumes-consecutive-base: Plans every run against the head it planned last, which is right only between neighbouring commits. Caught bywitness-transitiveEditTestat state 1, afteredit(file='beta', target='').cache-key-omits-test-roots: Leaves test_roots out of the cached graph's key, so a graph built for the old roots is reused after they change. Caught bywitness-narrowedTestRootsReplanFromScratchTestat state 2, aftertoggleConfig(file='narrow', target='').parse-cache-keyed-by-path: Caches parsed files by path instead of content, so an edited file keeps its old imports. Caught bywitness-importDeclarationFollowsImportsTestat state 3, afteredit(file='beta', target='').cache-checksum-ignored: Trusts a stored graph without checking its checksum, so a damaged entry is used as if it were valid. Caught bywitness-damagedCacheIsRebuiltTestat state 2, aftercorrupt(file='', target='').
Generated by pytest-quint-connect from contract receipts; what a passing run proves.
Reviewed duplication debt · Counts from the committed baselines.
| Accepted pairs | Remaining | Retired | Dismissed |
|---|---|---|---|
| Functions | 0 | 9 | 0 |
| Models | Not initialized | — | — |
Accepted backlog · Weekly audit
Retired means a side was removed, or (functions only) the judge now finds the pair separate. It is not a count of refactors. Dismissals stay separate; an uninitialized model baseline is unknown.
Metadata
Release files for pytest-selective 1.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_selective-1.9.1.tar.gz | 698.0 kB | With provenance | Details for pytest_selective-1.9.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_selective-1.9.1-py3-none-any.whl | Python 3 | none | any | Details for pytest_selective-1.9.1-py3-none-any.whl |
Total release size: 812.6 kB
Release files / pytest_selective-1.9.1.tar.gz
| Download URL | pytest_selective-1.9.1.tar.gz |
|---|---|
| Size | 698.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b87834e37cf9861a3bba0860eca9510cd6d21dd89a3d5d4a63d33a38f3761f22
|
|
BLAKE2b-256 checksum How to use checksums |
d85d0f5b590eaa36885a45611cbf581b3daa46dc3b01d0f884cdc10c3526fddd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logRelease files / pytest_selective-1.9.1-py3-none-any.whl
| Download URL | pytest_selective-1.9.1-py3-none-any.whl |
|---|---|
| Size | 114.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c315e8314bb62ef7c7d801f8b4d3ccf6daf32f09ff7cff4e75c877deb3e27ba
|
|
BLAKE2b-256 checksum How to use checksums |
82bc77841e58fe96a9008fe1cef05b77bdaf011af795748aa9752a40527b233b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logSecurity for pytest-selective 1.9.1
Provenance
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pytest_selective-1.9.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.
Transparency logA 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.