pytest-parametrized


Namepytest-parametrized JSON
Version 1.5 PyPI version JSON
download
home_page
SummaryPytest decorator for parametrizing tests with default iterables.
upload_time2023-11-03 18:29:00
maintainer
docs_urlNone
author
requires_python>=3.8
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)
[![image](https://github.com/coady/pytest-parametrized/workflows/build/badge.svg)](https://github.com/coady/pytest-parametrized/actions)
[![image](https://codecov.io/gh/coady/pytest-parametrized/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/pytest-parametrized/)
[![image](https://github.com/coady/pytest-parametrized/workflows/codeql/badge.svg)](https://github.com/coady/pytest-parametrized/security/code-scanning)
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)

[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
```

## 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": "",
    "name": "pytest-parametrized",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "pytest,parametrize,parameterize,fixture",
    "author": "",
    "author_email": "Aric Coady <aric.coady@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/e4/94/d5880bfaac8b843930db953b4d79229df5aa0948c0f4c2dd8f85b8b068ce/pytest-parametrized-1.5.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[![image](https://github.com/coady/pytest-parametrized/workflows/build/badge.svg)](https://github.com/coady/pytest-parametrized/actions)\n[![image](https://codecov.io/gh/coady/pytest-parametrized/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/pytest-parametrized/)\n[![image](https://github.com/coady/pytest-parametrized/workflows/codeql/badge.svg)](https://github.com/coady/pytest-parametrized/security/code-scanning)\n[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)\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## 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.5",
    "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": "0d467e8b2440479fc2760abdae5ed11a37b98dba40ee92b72a0788ac3e8c8fdd",
                "md5": "a78ceff374a514dde647cedfd42764e1",
                "sha256": "56d698e3ce48d7150644548616c1569679c17aeb7f448dc969f18ba0e5fa4a17"
            },
            "downloads": -1,
            "filename": "pytest_parametrized-1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a78ceff374a514dde647cedfd42764e1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 3711,
            "upload_time": "2023-11-03T18:28:58",
            "upload_time_iso_8601": "2023-11-03T18:28:58.924375Z",
            "url": "https://files.pythonhosted.org/packages/0d/46/7e8b2440479fc2760abdae5ed11a37b98dba40ee92b72a0788ac3e8c8fdd/pytest_parametrized-1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e494d5880bfaac8b843930db953b4d79229df5aa0948c0f4c2dd8f85b8b068ce",
                "md5": "010cad1c13776519f0050e2f2f21e0ea",
                "sha256": "b1d2f15786eb9285ece4b1a95acfd5eb765120188e2fddee0db92ddf86a0398d"
            },
            "downloads": -1,
            "filename": "pytest-parametrized-1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "010cad1c13776519f0050e2f2f21e0ea",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3686,
            "upload_time": "2023-11-03T18:29:00",
            "upload_time_iso_8601": "2023-11-03T18:29:00.850686Z",
            "url": "https://files.pythonhosted.org/packages/e4/94/d5880bfaac8b843930db953b4d79229df5aa0948c0f4c2dd8f85b8b068ce/pytest-parametrized-1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-03 18:29:00",
    "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.14106s