Error " Indirect fixture" when using pytest with a python factorial function

Asked

Viewed 48 times

0

I’m studying recursion and automated testing and decided to implement a recursive factorial:

   def fatorial(n):
    if n <= 1:
        return 1
    else:
        return n*fatorial(n - 1)


import pytest

@pytest.mark.parametrize("entrada","esperado",[
    (0,1),
    (1,1),
    (2,2),
    (3,6),
    (4,24),
    (5,120)
])

def testa_fatorial(entrada,esperado):
    assert fatorial(entrada)  == esperado

I don’t know why the pytest is showing the error:

 ERROR collecting Fatorial_pytest.py ____________________________________________________________________
In testa_fatorial: indirect fixture '(0, 1)' doesn't exist

Apparently, the test is correct. Any ideas? I’m using python 3.7 in windows 10 64 bits

1 answer

0


Try to put everything in one line:

@pytest.mark.parametrize("entrada","esperado",[(0,1),(1,1),(2,2),(3,6),(4,24),(5,120)])

or add a \at the end of each line to say pro python that the command continues on the next line.

@pytest.mark.parametrize("entrada","esperado",[\
    (0,1),\
    (1,1),\
    (2,2),\
    (3,6),\
    (4,24),\
    (5,120)\
]

Browser other questions tagged

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