pytest-parametrization

2022.2.1 · active · verified Thu Apr 16

pytest-parametrization is a Pytest plugin that aims to provide a simpler and more explicit way to parametrize test functions compared to the built-in `@pytest.mark.parametrize` decorator. It allows for clearer definition of test cases by separating parameter names from their values. The current version is 2022.2.1, with an irregular release cadence; the last PyPI update was in May 2022.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to use the `@parametrize` decorator from the `pytest-parametrization` plugin. It allows defining parameters using keyword arguments, where the values for each parameter are lists. The plugin also supports custom test IDs.

from parametrization import parametrize
import pytest

@parametrize(
    a=[1, 2],
    b=[2, 4]
)
def test_addition(a, b):
    assert a + b == a + b

@parametrize(
    num=[(1, 'one'), (2, 'two')],
    ids=['test_one', 'test_two']
)
def test_number_to_word(num, ids):
    number, word = num
    if number == 1:
        assert word == 'one'
    elif number == 2:
        assert word == 'two'

# To run: pytest -v your_test_file.py

view raw JSON →