Issue
I am trying to test a function multiple times using different parameters. The return value should be True.
def testConfiguration(small,medium,large):
...
if (everything goes well):
return True
else:
return False
testConfiguration(0,0,1)
testConfiguration(1,2,1)
testConfiguration(1,3,1)
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
def test_ConfigA():
assert testConfiguration(0,0,1) == True
def test_ConfigB():
assert testConfiguration(1,2,1) == True
...
Solution
Use @pytest.mark.parametrize()
@pytest.mark.parametrize("small, medium, large, out", [
(0,1,1, True),
(1,2,1, True),
(1,1,1, False),
])
def test_all(small, medium, large, out):
assert testConfiguration(small, medium, large) == out
Answered By - mx0
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.