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

Asked

Viewed 111 times

0

How do I separate the parametrize, the input from the expected

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

def testa_raizes(entrada, esperado):
    assert b.calcula_raizes(entrada) == (esperado)
  • In what function are you applying this decorator? You set the arguments as entrada and esperado?

  • Yes, I just edited the question, posting the method that receives the input and the expected value to be tested.

2 answers

0

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

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

You want to use two sequences at once, in a single test - then 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 yes, pytest takes the first element from the list of entries you pass in the parametrize - this element is [(1,0,0,), (1,0,)],. He takes the first helmet from there - (1,0,0) and passes as "input", and (1,0) as "expected".

0

Try this, considering you may have passed parameters a,b,c :

@pytest.mark.parametrize('entrada1, entrada2, entrada3, esperado', [(1,0,0,(1,0))])

def testa_raizes(entrada1, entrada2, entrada3, esperado):
    assert b.calcula_raizes(entrada1, entrada2, entrada3) == esperado

Browser other questions tagged

You are not signed in. Login or sign up in order to post.