2

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

...
3

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.