pytest-subset
A pytest plugin for deterministically sampling a subset of a heavily parametrized test's variants.
Installation
uv pip install pytest-subset
Usage
import pytest
@pytest.mark.subset(fraction=0.2)
@pytest.mark.parametrize("value", range(1000))
def test_something(value):
...
Running pytest normally will run ~20% of test_something's variants,
chosen deterministically. Pass --full (or -F) to run every variant,
e.g. in CI before a release.
Marker reference
@pytest.mark.subset(fraction=..., seed=None)
fraction: float in(0, 1]. Fraction of parametrized variants to keep. Optional ifsubset_default_fractionis set in yourpyproject.toml.seed: optional int. A seed value used to generate a pseudo-random slice of the parametric test space. Pins the selection for this test. If not provided, a default seed is generated based on the test module and Node ID. In either case, a given seed value will always generate the same subset of tests (i.e. deterministic)
CLI options
-F,--full— ignore everysubsetmarker and run all variants.--salt=SEED— controls the slice for tests that don't pin their ownseed=. Accepts:- an integer, so different values give different, still-reproducible slices;
random, to pick a fresh seed each run. It's printed after the run so you can reuse it later.
import pytest
@pytest.mark.subset(fraction=0.2, seed=42)
@pytest.mark.parametrize("value", range(1000))
def test_something(value):
...
@pytest.mark.subset(fraction=0.2)
@pytest.mark.parametrize("value", range(1000))
def test_something_else(value):
...
test_something always uses seed 42 — an explicit seed= superceeds
--salt every time. test_something_else has no seed of its own, so
--salt decides its slice:
pytest --salt=22 # test_something_else samples using salt 22
pytest --salt=random # a fresh seed is picked and printed after the run
Note that --salt=random picks each run's slice independently, so
slices across runs are not guaranteed to be disjoint.
Distributed runs (pytest-xdist)
pytest-subset is compatible with pytest-xdist; -n needs no extra flags.
xdist has known limitations, requiring every worker to collect the same tests in the same order. To account for this, the
plugin resolves the salt once on the controller and hands it to each worker.
That includes --salt=random: all workers share the one freshly picked seed,
and the value printed after the run reproduces the distributed selection exactly.
Note:
xdistsupport was only added inv0.2.0.
pytest -n auto --salt=random
Ini options
Set this under [tool.pytest.ini_options] in your pyproject.toml (or the
equivalent section of pytest.ini/setup.cfg):
subset_default_fraction— fraction used by@pytest.mark.subsetwhen it's applied bare, with nofraction=argument. This value is applied globally across the test suite.[tool.pytest.ini_options] subset_default_fraction = "0.3"
Then, in your test modules,
import pytest
@pytest.mark.subset # 0.3 applied here by default.
@pytest.mark.parametrize("value", range(1000))
def test_something(value):
...
Metadata
Release files for pytest-subset 0.2.0
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_subset-0.2.0.tar.gz | 9.4 kB | With provenance | Details for pytest_subset-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_subset-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_subset-0.2.0-py3-none-any.whl |
Total release size: 16.1 kB
Release files / pytest_subset-0.2.0.tar.gz
| Download URL | pytest_subset-0.2.0.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e84ecd8553870bd4e77c0793d43df3644ecebc4cb8883621dd141cfbdbbce9f
|
|
BLAKE2b-256 checksum How to use checksums |
4e9ace09081c99663dbdfca3baec5887e7781ad89b8ca1e7ce67a5bd188daa7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 14, 2026.
Transparency logRelease files / pytest_subset-0.2.0-py3-none-any.whl
| Download URL | pytest_subset-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61eadfd3a83fe3c2b1749ef7cf925af7fc0a77e69bbcebf0cfee1943993d4596
|
|
BLAKE2b-256 checksum How to use checksums |
e7450ba4f5e49afa349531a6c9dae91858ae16e5134d6e4af8c9bd003c2fe579
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 14, 2026.
Transparency logSecurity for pytest-subset 0.2.0
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_subset-0.2.0.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 Aug 14, 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.