Project: pytest-parametrization

Simpler PyTest parametrization

Project Details

Latest version
2022.2.1
Home Page
https://github.com/singular-labs/parametrization
PyPI Page
https://pypi.org/project/pytest-parametrization/

Project Popularity

PageRank
0.0015789502261375425
Number of downloads
129735

pytest-parametrization

Simpler PyTest parametrization

How to install

pip install pytest-parametrization

How to use

Explicit parameters

from parametrization import Parametrization
 
@Parametrization.parameters("actual", "expected")
@Parametrization.case(name="some_case_0", actual=1, expected=2)
@Parametrization.case("some_case_1", actual=1, expected=2)
@Parametrization.case("some_case_2", 1, expected=1)
@Parametrization.case("some_case_3", 2, 2)
@Parametrization.case("some_case_4", 3, 3)
def test_somthing(actual, expected):
    assert actual == expected

Auto-detect parameters

from parametrization import Parametrization
 
@Parametrization.autodetect_parameters()
@Parametrization.case(name="some_case_0", actual=1, expected=2)
@Parametrization.case("some_case_1", actual=1, expected=2)
@Parametrization.case("some_case_2", actual=1, expected=1)
def test_somthing(actual, expected):
    assert actual == expected

Auto-detect parameters with default parameter

from parametrization import Parametrization
 
@Parametrization.autodetect_parameters()
@Parametrization.default_parameters(expected=None)
@Parametrization.case(name="some_case_0", actual=1, expected=2)
@Parametrization.case("some_case_1", actual=1, expected=2)
@Parametrization.case("some_case_2", actual=1, expected=1)
@Parametrization.case("some_case_2", actual=1)
def test_somthing(actual, expected):
    assert actual == expected

Generate name based on arguments

from parametrization import Parametrization

@Parametrization.name_factory(lambda actual, expected: '{}=={}'.format(actual, expected))
@Parametrization.case(actual=1, expected=1)
@Parametrization.case(actual=2, expected=2)
@Parametrization.case('special-name', actual=3, expected=3)
def test_somthing(actual, expected):
    assert actual == expected

As can be seen from the example, you can also give explicit name for a case even if you are using name factory.