pytest-parametrized


Namepytest-parametrized JSON
Version 1.6 PyPI version JSON
download
home_pageNone
SummaryPytest decorator for parametrizing tests with default iterables.
upload_time2024-10-22 02:47:37
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseCopyright 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.
keywords pytest parametrize parameterize fixture
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![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.9",
    "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/be/da/2f836df67862093c6a0b93ac3bd9347203e8ebb496c1a77b243dabe43ca2/pytest_parametrized-1.6.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.6",
    "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": "d833c5be04a8f6835ad0aee37bd0dd5bac62c4bb278b7a8abaf83a41092b2e6b",
                "md5": "869ae1982f0cf4e42cf16bc7a18f0de8",
                "sha256": "541676cb1f1a22415fd5dc94440db64b6cb6bc9131eb8180c792ce3b68bb6027"
            },
            "downloads": -1,
            "filename": "pytest_parametrized-1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "869ae1982f0cf4e42cf16bc7a18f0de8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 3826,
            "upload_time": "2024-10-22T02:47:34",
            "upload_time_iso_8601": "2024-10-22T02:47:34.960011Z",
            "url": "https://files.pythonhosted.org/packages/d8/33/c5be04a8f6835ad0aee37bd0dd5bac62c4bb278b7a8abaf83a41092b2e6b/pytest_parametrized-1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "beda2f836df67862093c6a0b93ac3bd9347203e8ebb496c1a77b243dabe43ca2",
                "md5": "a9c0c0de4822b32cfa508392bba2cf28",
                "sha256": "d4fbc69efc0816fa051e1b08c2ff2d9cbb3d0b8dce256f84c909c6d6921c44e3"
            },
            "downloads": -1,
            "filename": "pytest_parametrized-1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "a9c0c0de4822b32cfa508392bba2cf28",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 3663,
            "upload_time": "2024-10-22T02:47:37",
            "upload_time_iso_8601": "2024-10-22T02:47:37.409542Z",
            "url": "https://files.pythonhosted.org/packages/be/da/2f836df67862093c6a0b93ac3bd9347203e8ebb496c1a77b243dabe43ca2/pytest_parametrized-1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-22 02:47:37",
    "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"
}
        
Elapsed time: 0.92483s