Skip to main content

Pytest plugin for parametrizing tests with default iterables.

Project description

image image image image image image image

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

Usage

Decorate tests with iterable default values.

functions

@pytest.parametrized
def test(name=values, ...):
    """test single parametrized arg with each value"""

@pytest.parametrized.zip
def test(name=values, name1=values1, ...):
    """test parametrized args with zipped values"""

@pytest.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

@pytest.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

@pytest.parametrized.product
def test_foo(x=(0, 1), y=(2, 3)):
    pass

fixtures

Parametrized fixtures which simply return their param.

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

Before and after example:

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

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

Installation

$ pip install pytest-parametrized

Require plugin as usual in conftest.py.

pytest_plugins = 'parametrized', ...

Tests

100% branch coverage.

$ pytest [--cov]

Changes

1.0

  • parametrized keyword options

0.2

  • fixture keyword options

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.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

pytest_parametrized-1.0-py2.py3-none-any.whl (3.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-parametrized-1.0.tar.gz.

File metadata

  • Download URL: pytest-parametrized-1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for pytest-parametrized-1.0.tar.gz
Algorithm Hash digest
SHA256 a5b399112bb6bd27b038887a80c8502b70e638deb8036f342e231ed4754e42ac
MD5 14ff8b8b954a2afbf1d7281f1158a90a
BLAKE2b-256 713fbf9f880c0aad3ae7db76574150e96f1d066a2fc3264ec7d7782999d0a240

See more details on using hashes here.

File details

Details for the file pytest_parametrized-1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pytest_parametrized-1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for pytest_parametrized-1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 92b3ff00fd322d34829d8b27724b678f3457bb35580e8a8d3a5997293b63d6dc
MD5 b0855295e134af2ef532e16eecb1584d
BLAKE2b-256 04aa3039bfea8336de231d9e986b376ebff003ef2b020222b4e9f001fb0cf99a

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