pytest-sample-argvalues
A utility function to help choose a random sample from your argvalues in pytest
Install
pip install pytest-sample-argvalues
Why would I need this?
One of the cool features of pytest is that you can stack multiple instances of pytest.mark.parametrize, to get all combinations of multiple parametrized arguments. See the docs for full details. For instance:
import pytest
@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
def test_foo(x, y):
pass
# This will run the test with the arguments set to x=0/y=2, x=1/y=2, x=0/y=3, and x=1/y=3 exhausting parameters in the order of the decorators.
However, it quickly becomes apparent that this product of parameters can grow vey quickly, leading to too many tests...
Example Usage
This package present an easy method of taking a random sample of your multiple parametrized arguments. This is useful if you don't have time to run all of your tests (or there are simply too many!), and want to check a random sample of them, to find any potential bugs. For instance,
import pytest
from pytest_argvalues_sample import pytest_argvalues_sample
MAX_TESTS = 1_000
SAMPLE_FRACTION = 0.000001
PARAMS = {
"a": list(range(1000)),
"b": list(range(1000)),
"c": list(range(1000)),
}
@pytest.mark.parametrize(
"a,b,c",
argvalues=pytest_argvalues_sample(PARAMS, SAMPLE_FRACTION, MAX_TESTS)
)
def test_param_sample(a: int, b: int, c: int):
assert a + b + c <= 2997
Instead of attempting to run 1000**3 pytests, this will run (1000**3)*0.000001=1000 pytests.
Release files for pytest-sample-argvalues 0.0.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 | |
|---|---|---|---|
| pytest_sample_argvalues-0.0.1.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_sample_argvalues-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.7 kB
Release files / pytest_sample_argvalues-0.0.1.tar.gz
| Download URL | pytest_sample_argvalues-0.0.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d246b8ed9784a46c435ff79fe1680c573855290a433d0512dfd5cb64c25f6c8
|
|
BLAKE2b-256 checksum How to use checksums |
e28ed5d87eb77bb09835bc266f7bc8fc02aae11ada8d827463e01812fff655c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.11
|
Release files / pytest_sample_argvalues-0.0.1-py3-none-any.whl
| Download URL | pytest_sample_argvalues-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
98b13c3d5f8e96a0ec8065c98ebad66f137513231f9a8bab49199f205510be7d
|
|
BLAKE2b-256 checksum How to use checksums |
1af4ffaf2cbf5708b658eaa7da6dcf3f6b1645be07a2e7de3a631102f7bd99c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.11
|