https://github.com/coady/pytest-parametrized
Pytest decorator for parametrizing tests with default iterables.
https://github.com/coady/pytest-parametrized
fixture parameterize parametrize pytest
Last synced: 10 months ago
JSON representation
Pytest decorator for parametrizing tests with default iterables.
- Host: GitHub
- URL: https://github.com/coady/pytest-parametrized
- Owner: coady
- License: other
- Created: 2017-10-20T02:29:38.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-08-21T20:01:56.000Z (10 months ago)
- Last Synced: 2025-08-21T21:49:40.167Z (10 months ago)
- Topics: fixture, parameterize, parametrize, pytest
- Language: Python
- Homepage:
- Size: 63.5 KB
- Stars: 19
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://pypi.org/project/pytest-parametrized/)

[](https://pepy.tech/project/pytest-parametrized)

[](https://github.com/coady/pytest-parametrized/actions/workflows/build.yml)
[](https://codecov.io/gh/coady/pytest-parametrized/)
[](https://github.com/coady/pytest-parametrized/actions/workflows/github-code-scanning/codeql)
[](https://github.com/astral-sh/ruff)
[Pytest](https://pytest.org/) decorator for parametrizing tests with default iterables, providing alternative syntax for [pytest.mark.parametrize](https://docs.pytest.org/en/latest/how-to/parametrize.html).
# Usage
Decorate tests with iterable default values. Other fixtures can still be used as normal.
## functions
```python
from parametrized import parametrized
@parametrized
def test(..., name=values):
"""test single parametrized arg with each value"""
@parametrized.zip
def test(name=values, name1=values1, ...):
"""test parametrized args with zipped values"""
@parametrized.product
def test(name=values, name1=values1, ...):
"""test parametrized args with cartesian product of values"""
```
Zip before and after example:
```python
@pytest.mark.parametrize("test_input,expected", [
("3+5", 8),
("2+4", 6),
("6*9", 42),
])
def test_eval(test_input, expected):
assert eval(test_input) == expected
@parametrized.zip
def test_eval(test_input=["3+5", "2+4", "6*9"], expected=[8, 6, 42]):
assert eval(test_input) == expected
```
Product before and after example:
```python
@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
def test_foo(x, y):
pass
@parametrized.product
def test_foo(x=[0, 1], y=[2, 3]):
pass
```
`pytest.param` is supported for single values or `.product`.
## fixtures
[Parametrized fixtures](https://docs.pytest.org/en/latest/how-to/fixtures.html#fixture-parametrize) which simply return their param.
```python
fixture_name = parametrized.fixture(*params, **kwargs)
```
Before and after example:
```python
@pytest.fixture(params=[0, 1], ids=["spam", "ham"])
def a(request):
return request.param
a = parametrized.fixture(0, 1, ids=["spam", "ham"])
```
# Installation
```console
% pip install pytest-parametrized
```
# Tests
100% branch coverage.
```console
% pytest [--cov]
```