Parametrize
The parametrize tag allows us to run the same test with several different inputs.
This works like pytest's parametrize decorator.
Basic Usage
First, here is a small example:
| test.py | |
|---|---|
1 2 3 4 5 | |
Running uv run karva test will run test_function three times, once for each value of a.
Multiple Variables
We can also parametrize multiple arguments:
| test.py | |
|---|---|
1 2 3 4 5 | |
Like pytest, we can put the arguments in a single string, separated by ",":
| test.py | |
|---|---|
1 2 3 4 5 | |
Parametrize with Fixtures
We can also mix fixtures and parametrize:
| test.py | |
|---|---|
1 2 3 4 5 6 7 8 9 | |
Each parametrized variant receives the fixture value alongside the parametrized arguments.
Multiple Parametrize Tags
We can also use multiple decorators, allowing us to test more scenarios. This will result in a cartesian product of the parametrize values.
| test.py | |
|---|---|
1 2 3 4 5 6 | |
This runs test_function four times with all combinations of a and b.
Params
You can use karva.param (similar to pytest.param) to attach tags to individual parameter sets:
| test.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 | |
Pytest
You can also still use @pytest.mark.parametrize:
| test.py | |
|---|---|
1 2 3 4 5 | |