I am trying to test a function multiple times using different parameters. The return value should be True.
JavaScript
x
11
11
1
def testConfiguration(small,medium,large):
2
3
if (everything goes well):
4
return True
5
else:
6
return False
7
8
testConfiguration(0,0,1)
9
testConfiguration(1,2,1)
10
testConfiguration(1,3,1)
11
What’s the best way to go about doing this in pytest? I want to avoid multiple functions acting as assert True wrappers e.g
JavaScript
1
8
1
def test_ConfigA():
2
assert testConfiguration(0,0,1) == True
3
4
def test_ConfigB():
5
assert testConfiguration(1,2,1) == True
6
7
8
Advertisement
Answer
Use @pytest.mark.parametrize()
JavaScript
1
8
1
@pytest.mark.parametrize("small, medium, large, out", [
2
(0,1,1, True),
3
(1,2,1, True),
4
(1,1,1, False),
5
])
6
def test_all(small, medium, large, out):
7
assert testConfiguration(small, medium, large) == out
8