Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does indirect = True/False in pytest.mark.parametrize do/mean?

Tags:

python

pytest

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

like image 289
Froodo Avatar asked Feb 15 '16 15:02

Froodo


People also ask

What is indirect in pytest?

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.

What is Parametrize in 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.

Which arguments can we pass to pytest Mark Parametrize to simplify testing Python code?

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.


1 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.

like image 158
Sergey Voronezhskiy Avatar answered Sep 28 '22 02:09

Sergey Voronezhskiy