Skip to main content

pytest-selective: Run affected Python tests. See why they matter.

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

Detailed adoption reference — installation options, selection guarantees, benchmarks and tool comparisons.

Project quality checks

What pytest-quint-connect's contracts caught in gigaverse-app/pytest-selective's pull requests

Quint contracts: 1 contract passed · 49 histories · 14/14 planted bugs caught

Contract Cases passed Planted bugs caught
✅ selection test_selection_contract.py::test_selection
49 histories (25 witnesses, 24 samples, seed 11) · every action covered · Quint 0.33.1
64/64 14/14

Bugs this contract found

  1. 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 test tests/testing/test_impact_graph.py::test_star_import_reaches_the_submodules_its_package_lists_in_all. 1 of 49 histories diverge when planted bug star-exports-ignored (Reintroduces the star-import bug: from pkg import * no longer reaches the submodules pkg lists in all) reintroduces it; first caught by witness-starImportFollowsAllTest at state 2, after edit(file='alpha', target='').
  2. Editing a plugin loaded by addopts = -p NAME selected 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 test tests/testing/test_impact_graph.py::test_command_line_plugin_in_addopts_reaches_every_test. 2 of 49 histories diverge when planted bug addopts-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 by witness-commandLinePluginSelectsEveryTestTest at state 1, after edit(file='plugin', target='').
  3. A bare import helpers resolved 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 test tests/testing/test_impact_graph.py::test_bare_import_resolves_from_the_importers_prepend_mode_base_directory. 1 of 49 histories diverge when planted bug prepend-roots-ignored (Reintroduces the import-mode bug: imports no longer resolve from the directories pytest prepends to sys.path) reintroduces it; first caught by witness-bareTestImportFollowsPrependModeTest at state 2, after edit(file='helper', target='').
  4. 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 bug literal-reads-ignored (Reintroduces the literal-read bug: open('data/table.json') no longer makes the reader depend on that file) reintroduces it; first caught by witness-literalPathReadTest at state 2, after edit(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 by witness-deletedModuleSelectsFormerImportersTest at state 1, after remove(file='beta', target='').
  • direct-importers-only: Follows only files that import a changed file directly, not their importers. Caught by witness-transitiveEditTest at state 1, after edit(file='beta', target='').
  • global-inputs-ignored: Treats requirements.txt like any unreferenced file instead of selecting every test. Caught by witness-globalInputSelectsEveryTestTest at state 1, after touchGlobal(file='', target='').
  • content-follows-imports: Reads a kind: content declaration as an import, so it also follows the read file's imports. Caught by witness-contentReadIsNotTransitiveTest at state 2, after edit(file='beta', target='').
  • conftest-scope-collapsed: Scopes every conftest to the top test directory, so tests/sub/conftest.py reaches every test. Caught by witness-nestedConftestSelectsItsSubtreeTest at state 1, after edit(file='subconftest', target='').
  • parse-errors-ignored: Treats an unparseable file as importing nothing instead of stopping with an error. Caught by witness-unparseableSourceIsAnErrorTest at state 1, after breakSyntax(file='beta', target='').
  • assumes-consecutive-base: Plans every run against the head it planned last, which is right only between neighbouring commits. Caught by witness-transitiveEditTest at state 1, after edit(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 by witness-narrowedTestRootsReplanFromScratchTest at state 2, after toggleConfig(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 by witness-importDeclarationFollowsImportsTest at state 3, after edit(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 by witness-damagedCacheIsRebuiltTest at state 2, after corrupt(file='', target='').

Generated by pytest-quint-connect from contract receipts; what a passing run proves.

dry-lint in gigaverse-app/pytest-selective: new duplicates kept out of its pull requests, 9 old duplicates cleaned up, 0 remaining

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)

Source distribution for pytest-selective 1.9.1
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)

Table of built distributions (wheels) for pytest-selective 1.9.1
File Interpreter ABI Platform Actions
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 log

Release 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 log

Security 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.

Select from 2 files

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 log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page