Metadata-Version: 2.1
Name: pytest-sample-argvalues
Version: 0.0.1
Summary: A utility function to help choose a random sample from your argvalues in pytest.
Author: Adam Powis
License: MIT License
        
        Copyright (c) 2024 Adam Powis
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.8.0
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: iteration-utilities
Requires-Dist: pytest
Provides-Extra: test
Requires-Dist: pylint; extra == "test"

# pytest-sample-argvalues
A utility function to help choose a random sample from your argvalues in pytest

## Install
```python
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](https://docs.pytest.org/en/7.1.x/how-to/parametrize.html) for full details. For instance:
```python
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,

```python
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.
