pypipython-3.x95% confidence\u2191 65

“ indirect fixture” error using pytest. What is wrong?

Full error message
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

The error:

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

I dont know why I got "indirect fixture”. Any idea?
I am using python 3.7 and windows 10 64 bits.

TL;DR - The problem is with the line @pytest.mark.parametrize("entrada","esperado",[ ... ]) It should be written as a comma-separated string: @pytest.mark.parametrize("entrada, esperado",[ ... ]) You got the indirect fixture because pytest couldn't unpack the given argvalues since it got a wrong argnames parameter. You need to make sure all parameters are written as one string. Please see the documentation: The builtin pytest.mark.parametrize decorator enables parametrization of arguments for a test function. Parameters: 1. argnames – a comma-separated string denoting one or more argument names, or a list/tuple of argument strings. 2. argvalues – The list of argvalues determines how often a test is invoked with different argument values. Meaning, you should write the arguments you want to parametrize as a single string and separate them using a comma. Therefore, your test should look like this: @pytest.mark.parametrize("n, expected", [ (0, 1), (1, 1), (2, 2), (3, 6), (4, 24), (5, 120) ]) def test_factorial(n, expected): assert factorial(n) == expected

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/e651f0efaefd22eb50ebe7737c9da23d3b9e2b81e99af4394d65eea77912456b
hash \u00b7 e651f0efaefd22eb50ebe7737c9da23d3b9e2b81e99af4394d65eea77912456b
“ indirect fixture” error using pytest. What is wrong? — DepScope fix | DepScope