Pytest plugin for parametrizing tests with default iterables.
Project description
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
Built Distribution
Close
Hashes for pytest_parametrized-1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92b3ff00fd322d34829d8b27724b678f3457bb35580e8a8d3a5997293b63d6dc |
|
MD5 | b0855295e134af2ef532e16eecb1584d |
|
BLAKE2b-256 | 04aa3039bfea8336de231d9e986b376ebff003ef2b020222b4e9f001fb0cf99a |