What does indirect = True/False in pytest.mark.parametrize do/mean?
Question:
I just want to understand what does it mean or what happens if I set indirect parameter to True
or False
in the pytest.mark.parametrize
?
Answers:
With indirect=True
you can parametrize your fixture, False
– default value. Example:
import pytest
@pytest.fixture
def fixture_name(request):
return request.param
@pytest.mark.parametrize('fixture_name', ['foo', 'bar'], indirect=True)
def test_indirect(fixture_name):
assert fixture_name == 'baz'
So this example generates two tests. First one gets from fixture_name
value foo, because this fixture for this test runs with parametization. Second test gets bar value. And each tests will fail, because of assert checking for baz.
I just want to understand what does it mean or what happens if I set indirect parameter to True
or False
in the pytest.mark.parametrize
?
With indirect=True
you can parametrize your fixture, False
– default value. Example:
import pytest
@pytest.fixture
def fixture_name(request):
return request.param
@pytest.mark.parametrize('fixture_name', ['foo', 'bar'], indirect=True)
def test_indirect(fixture_name):
assert fixture_name == 'baz'
So this example generates two tests. First one gets from fixture_name
value foo, because this fixture for this test runs with parametization. Second test gets bar value. And each tests will fail, because of assert checking for baz.