Skip to main content

Pytest decorator for parametrizing tests with default iterables.

Project description

image image image image build image CodeQL image

Pytest decorator for parametrizing tests with default iterables, providing alternative syntax for pytest.mark.parametrize.

Usage

Decorate tests with iterable default values. Other fixtures can still be used as normal.

functions

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:

@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:

@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 which simply return their param.

fixture_name = parametrized.fixture(*params, **kwargs)

Before and after example:

@pytest.fixture(params=[0, 1], ids=["spam", "ham"])
def a(request):
    return request.param

a = parametrized.fixture(0, 1, ids=["spam", "ham"])

Installation

% pip install pytest-parametrized

Tests

100% branch coverage.

% pytest [--cov]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_parametrized-1.6.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

pytest_parametrized-1.6-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_parametrized-1.6.tar.gz.

File metadata

  • Download URL: pytest_parametrized-1.6.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytest_parametrized-1.6.tar.gz
Algorithm Hash digest
SHA256 d4fbc69efc0816fa051e1b08c2ff2d9cbb3d0b8dce256f84c909c6d6921c44e3
MD5 a9c0c0de4822b32cfa508392bba2cf28
BLAKE2b-256 beda2f836df67862093c6a0b93ac3bd9347203e8ebb496c1a77b243dabe43ca2

See more details on using hashes here.

File details

Details for the file pytest_parametrized-1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_parametrized-1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 541676cb1f1a22415fd5dc94440db64b6cb6bc9131eb8180c792ce3b68bb6027
MD5 869ae1982f0cf4e42cf16bc7a18f0de8
BLAKE2b-256 d833c5be04a8f6835ad0aee37bd0dd5bac62c4bb278b7a8abaf83a41092b2e6b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page