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?
Thanks
You can pass a keyword argument named indirect to parametrize to change how its parameters are being passed to the underlying test function. It accepts either a boolean value or a list of strings that refer to pytest.
@pytest. mark. parametrize allows one to define multiple sets of arguments and fixtures at the test function or class. pytest_generate_tests allows one to define custom parametrization schemes or extensions.
Summary. You can pass arguments to fixtures with the params keyword argument in the fixture decorator, and you can also pass arguments to tests with the @pytest.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With