[![image](https://img.shields.io/pypi/v/pytest-parametrized.svg)](https://pypi.org/project/pytest-parametrized/)
![image](https://img.shields.io/pypi/pyversions/pytest-parametrized.svg)
[![image](https://pepy.tech/badge/pytest-parametrized)](https://pepy.tech/project/pytest-parametrized)
![image](https://img.shields.io/pypi/status/pytest-parametrized.svg)
[![build](https://github.com/coady/pytest-parametrized/actions/workflows/build.yml/badge.svg)](https://github.com/coady/pytest-parametrized/actions/workflows/build.yml)
[![image](https://codecov.io/gh/coady/pytest-parametrized/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/pytest-parametrized/)
[![CodeQL](https://github.com/coady/pytest-parametrized/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/coady/pytest-parametrized/actions/workflows/github-code-scanning/codeql)
[![image](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](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]
```
Raw data
{
"_id": null,
"home_page": null,
"name": "pytest-parametrized",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "pytest, parametrize, parameterize, fixture",
"author": null,
"author_email": "Aric Coady <aric.coady@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/44/ae/8ed9bd7dee749610f4e1c52f1bc28f1dfc873f41fc54fcaf509e07829237/pytest_parametrized-1.7.tar.gz",
"platform": null,
"description": "[![image](https://img.shields.io/pypi/v/pytest-parametrized.svg)](https://pypi.org/project/pytest-parametrized/)\n![image](https://img.shields.io/pypi/pyversions/pytest-parametrized.svg)\n[![image](https://pepy.tech/badge/pytest-parametrized)](https://pepy.tech/project/pytest-parametrized)\n![image](https://img.shields.io/pypi/status/pytest-parametrized.svg)\n[![build](https://github.com/coady/pytest-parametrized/actions/workflows/build.yml/badge.svg)](https://github.com/coady/pytest-parametrized/actions/workflows/build.yml)\n[![image](https://codecov.io/gh/coady/pytest-parametrized/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/pytest-parametrized/)\n[![CodeQL](https://github.com/coady/pytest-parametrized/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/coady/pytest-parametrized/actions/workflows/github-code-scanning/codeql)\n[![image](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\n[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).\n\n# Usage\nDecorate tests with iterable default values. Other fixtures can still be used as normal.\n\n## functions\n```python\nfrom parametrized import parametrized\n\n@parametrized\ndef test(..., name=values):\n \"\"\"test single parametrized arg with each value\"\"\"\n\n@parametrized.zip\ndef test(name=values, name1=values1, ...):\n \"\"\"test parametrized args with zipped values\"\"\"\n\n@parametrized.product\ndef test(name=values, name1=values1, ...):\n \"\"\"test parametrized args with cartesian product of values\"\"\"\n```\n\nZip before and after example:\n```python\n@pytest.mark.parametrize(\"test_input,expected\", [\n (\"3+5\", 8),\n (\"2+4\", 6),\n (\"6*9\", 42),\n])\ndef test_eval(test_input, expected):\n assert eval(test_input) == expected\n\n@parametrized.zip\ndef test_eval(test_input=[\"3+5\", \"2+4\", \"6*9\"], expected=[8, 6, 42]):\n assert eval(test_input) == expected\n```\n\nProduct before and after example:\n```python\n@pytest.mark.parametrize(\"x\", [0, 1])\n@pytest.mark.parametrize(\"y\", [2, 3])\ndef test_foo(x, y):\n pass\n\n@parametrized.product\ndef test_foo(x=[0, 1], y=[2, 3]):\n pass\n```\n\n`pytest.param` is supported for single values or `.product`.\n\n## fixtures\n[Parametrized fixtures](https://docs.pytest.org/en/latest/how-to/fixtures.html#fixture-parametrize) which simply return their param.\n\n```python\nfixture_name = parametrized.fixture(*params, **kwargs)\n```\n\nBefore and after example:\n```python\n@pytest.fixture(params=[0, 1], ids=[\"spam\", \"ham\"])\ndef a(request):\n return request.param\n\na = parametrized.fixture(0, 1, ids=[\"spam\", \"ham\"])\n```\n\n# Installation\n```console\n% pip install pytest-parametrized\n```\n\n# Tests\n100% branch coverage.\n\n```console\n% pytest [--cov]\n```\n",
"bugtrack_url": null,
"license": "Copyright 2022 Aric Coady Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ",
"summary": "Pytest decorator for parametrizing tests with default iterables.",
"version": "1.7",
"project_urls": {
"Changelog": "https://github.com/coady/pytest-parametrized/blob/main/CHANGELOG.md",
"Homepage": "https://github.com/coady/pytest-parametrized",
"Issues": "https://github.com/coady/pytest-parametrized/issues"
},
"split_keywords": [
"pytest",
" parametrize",
" parameterize",
" fixture"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "926651fdf9cb516783cfa9363b587fd9a99f86726bd5606baa6c9adf0fa4b0d2",
"md5": "6088877197fdb191099f5f2bcb6d3158",
"sha256": "a7da6948c0ccb6798924f600b01c4c19064d46fd2bd49b5406c2d9aa7303d05e"
},
"downloads": -1,
"filename": "pytest_parametrized-1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6088877197fdb191099f5f2bcb6d3158",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 3822,
"upload_time": "2024-12-21T17:34:49",
"upload_time_iso_8601": "2024-12-21T17:34:49.951800Z",
"url": "https://files.pythonhosted.org/packages/92/66/51fdf9cb516783cfa9363b587fd9a99f86726bd5606baa6c9adf0fa4b0d2/pytest_parametrized-1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "44ae8ed9bd7dee749610f4e1c52f1bc28f1dfc873f41fc54fcaf509e07829237",
"md5": "3033c5e0559832f8767a01e27195d505",
"sha256": "3ec50eb164dae2ad3a0595ec197ff8bc1ce741342991f0016ba7daa6a861361b"
},
"downloads": -1,
"filename": "pytest_parametrized-1.7.tar.gz",
"has_sig": false,
"md5_digest": "3033c5e0559832f8767a01e27195d505",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 3712,
"upload_time": "2024-12-21T17:34:52",
"upload_time_iso_8601": "2024-12-21T17:34:52.606626Z",
"url": "https://files.pythonhosted.org/packages/44/ae/8ed9bd7dee749610f4e1c52f1bc28f1dfc873f41fc54fcaf509e07829237/pytest_parametrized-1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-21 17:34:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "coady",
"github_project": "pytest-parametrized",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pytest-parametrized"
}