diff --git a/_pytest/python.py b/_pytest/python.py index 622ed2a46..bf9be9f12 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -833,7 +833,7 @@ class Metafunc(FuncargnamesCompatAttr): """ Add new invocations to the underlying test function using the list of argvalues for the given argnames. Parametrization is performed during the collection phase. If you need to setup expensive resources - see about setting indirect=True to do it rather at test setup time. + see about setting indirect to do it rather at test setup time. :arg argnames: a comma-separated string denoting one or more argument names, or a list/tuple of argument strings. diff --git a/doc/en/example/parametrize.txt b/doc/en/example/parametrize.txt index d897cf762..71c37699d 100644 --- a/doc/en/example/parametrize.txt +++ b/doc/en/example/parametrize.txt @@ -280,6 +280,46 @@ The first invocation with ``db == "DB1"`` passed while the second with ``db == " .. regendoc:wipe +Apply indirect on particular arguments +--------------------------------------------------- + +Very often parametrization uses more than one argument name. There is opportunity to apply ``indirect`` +parameter on particular arguments. It can be done by passing list or tuple of +arguments' names to ``indirect``. In the example below there is a function ``test_indirect`` which uses +two fixtures: ``x`` and ``y``. Here we give to indirect the list, which contains the name of the +fixture ``x``. The indirect parameter will be applied to this argument only, and the value ``a`` +will be passed to respective fixture function. + + # content of test_indirect_list.py + + import pytest + @pytest.fixture(scope='function') + def x(request): + return request.param * 3 + + @pytest.fixture(scope='function') + def y(request): + return request.param * 2 + + @pytest.mark.parametrize('x, y', [('a', 'b')], indirect=['x']) + def test_indirect(x,y): + assert x == 'aaa' + assert y == 'b' + +The result of this test will be successful: + + $ py.test test_indirect_list.py --collect-only + ============================= test session starts ============================== + platform linux2 -- Python 2.7.3, pytest-2.8.0.dev4, py-1.4.30, pluggy-0.3.0 + rootdir: /home/elizabeth/work/pytest, inifile: tox.ini + collected 1 items + + + + =============================== in 0.02 seconds =============================== + +.. regendoc:wipe + Parametrizing test methods through per-class configuration --------------------------------------------------------------