i'm new to pytest so please bear with me.
i'm trying to use stack parametrize decorators to test multiple combination permutations, but the question is how can i use values from other parametrize decorators in the stack.
i found the following: but it is not exactly what i'm looking for
stacked parametrize
Using fixtures in pytest.mark.parametrize\
this is what i'm trying to achieve:
@pytest.mark.parametrize("environment", ["main", "develop", "ci"])
@pytest.mark.parametrize("model", get_models())
@pytest.mark.parametrize("id", get_ids(environment, model)) #here i tried to use the returned values of environment and model from the above decorators
def test_ids(environment, model, id):
another_method(environment, model, id)
# some logic here
get_ids()
returns a list of ids based on a given environment
and model
.
this solution doesn't work, since it raising an unresolved reference error for environment
and model
the reason that i want to use parametrize decorator is because i need to test all the permutations of environments
,models
and ids
, but want pytest to generate a separate test for each combination.
my current solution is:
@pytest.mark.parametrize("environment", ["main", "develop", "ci"])
@pytest.mark.parametrize("model", get_models())
def test_ids(environment, model):
ids = get_ids(environment, model)
for id in ids:
another_method(environment, model, id)
# some logic here
this solution works, but each test is very long since it's looping over a long list of ids,
i prefer running multiple small tests, rather than fewer tests but very long.
it makes it harder to understand what happen in the tests.
any suggestion?