Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Testing the same function with different parameters

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

...

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading