Separate input value and expected value in pytest.mark.parametrize

0

How do I separate the parametrize, the expected input

@pytest.mark.parametrize('entrada, esperado',
                         [(1,0,0,), (1,0,)
                        ])

def testa_raizes(entrada, esperado):
    assert b.calcula_raizes(entrada) == (esperado)
    
asked by anonymous 14.11.2017 / 12:11

1 answer

0

When you use the paramtrize, the second parameter is a sequence (which can be a list), or each element, and another sequence that contains an item for each function parameter.

You want the sequence (1, 0, 0) to be assigned the variable "input", however the way you did, pytest will pick up "1" and assign the "input" and "0" assign to "expected" (and probably give an error because there is a third 0 left).

You want to use these two sequences at once, in a single test - then you have to create a sequence with them:

@pytest.mark.parametrize('entrada, esperado', [
    [(1,0,0,), (1,0,)],
])
def testa_raizes(entrada, esperado):
    assert b.calcula_raizes(entrada) == (esperado)

Now, pytest takes the first element from the list of entries you pass in the parametrize - that element is [(1,0,0,), (1,0,)], . It gets the first element of it - (1,0,0) and passes as "input", and (1,0) as "expected".

    
17.11.2017 / 12:49