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

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)