pythonpytestparametrize

Using parametrize for multiple arguments in pytest


There is such a function:

def underscore_concat(*args):
    return "_".join(filter(None, ([*args]))).upper()

How to correctly pass multiple parameters using pytest.mark.parametrize?

Something like this:

@pytest.mark.parametrize("a, result", [(["underscore", "concat", "test"], "UNDERSCORE_CONCAT_TEST")])
def test_underscore_concat(a, result):
    assert underscore_concat(**a) == result

Solution

  • @pytest.mark.parametrize("a, result", [(["underscore", "concat", "test"], "UNDERSCORE_CONCAT_TEST")])
    def test_underscore_concat(a, result):
        assert underscore_concat(*a) == result