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 aren't guaranteed to be disjoint.
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):
...
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_subset-0.1.0.tar.gz.
File metadata
- Download URL: pytest_subset-0.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db473ac4b26001ff841dfe997537eee6adc8c0ca1ddfe04b4d4cbc644efdf61a
|
|
| MD5 |
49e631d95a410cf4e7070f6c5873ce4b
|
|
| BLAKE2b-256 |
242f54786ad5e8343e47f8a10cd9de98fb6826bb635afd3658ce91bc5cc40d25
|
Provenance
The following attestation bundles were made for pytest_subset-0.1.0.tar.gz:
Publisher:
publish.yml on cyber-paraphernalia/pytest-subset
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_subset-0.1.0.tar.gz -
Subject digest:
db473ac4b26001ff841dfe997537eee6adc8c0ca1ddfe04b4d4cbc644efdf61a - Sigstore transparency entry: 2341377133
- Sigstore integration time:
-
Permalink:
cyber-paraphernalia/pytest-subset@d577f9388796d0d0f4fd8c02304665bade0b005b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cyber-paraphernalia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d577f9388796d0d0f4fd8c02304665bade0b005b -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_subset-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_subset-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28d085f270863af125171c305539f7602569f7e957367b099a6f575736ebc209
|
|
| MD5 |
ceb99cf3f39ddf83003cbf04c8208d53
|
|
| BLAKE2b-256 |
89ee4f08b71253d82c16a9744127eab787eeb195a9397abd047c2b31c9ce753f
|
Provenance
The following attestation bundles were made for pytest_subset-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on cyber-paraphernalia/pytest-subset
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_subset-0.1.0-py3-none-any.whl -
Subject digest:
28d085f270863af125171c305539f7602569f7e957367b099a6f575736ebc209 - Sigstore transparency entry: 2341377146
- Sigstore integration time:
-
Permalink:
cyber-paraphernalia/pytest-subset@d577f9388796d0d0f4fd8c02304665bade0b005b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/cyber-paraphernalia
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d577f9388796d0d0f4fd8c02304665bade0b005b -
Trigger Event:
release
-
Statement type: