The function f
accepts keyword arguments, so you need to assign your test parameters to keywords. Luckily, Python provides a very handy way of passing keyword arguments to a function...the dictionary:
d = {'h': 4}
f(**d)
The **
prefix before d
will "unpack" the dictionary, passing each key/value pair as a keyword argument to the function.
For your pytest
example, this means you just need to replace the string parameter with a dictionary, and the eval
in test_f2
with the keyword unpacker:
@pytest.mark.parametrize("arg,expected", [
({'h':4}, 54),
({'g':20}, 102),
])
def test_f2(arg, expected):
assert f(**arg) == expected