Skip to content

Support indirect parametrization #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
smarie opened this issue Mar 31, 2021 · 1 comment
Open

Support indirect parametrization #194

smarie opened this issue Mar 31, 2021 · 1 comment

Comments

@smarie
Copy link
Owner

smarie commented Mar 31, 2021

Sometimes a fixture is parametrized with cases using @parametrize_with_cases, but for a specific test one would like to only select a subset of these cases. This would for example solve the need in #188

Indirect parametrization is the answer of pytest to this need. For example :

from pytest_cases import parametrize, fixture

@fixture
@parametrize(a=[0, 1])
def my_fix(a):
    return a * 2

@fixture
@parametrize(b=[0, 10])
def my_fix2(b, my_fix):
    return b + my_fix

def test_foo(my_fix2):
    assert my_fix2 in (0, 2, 10, 12)

@parametrize(my_fix=[2], indirect=True)
def test_foo_indirect(my_fix2):
    assert my_fix2 in (4, 14)

Leads to

test_indirect.py::test_foo[b=0-a=0] 
test_indirect.py::test_foo[b=0-a=1] 
test_indirect.py::test_foo[b=10-a=0] 
test_indirect.py::test_foo[b=10-a=1] 
test_indirect.py::test_foo_indirect[b=0-my_fix=2] 

Apart from the test id that is a bit fiddled with by pytest, the rest works as expected.
See also this article.

Now does this work with @parametrize_with_cases ? Does it work with @parametrize when there is a fixture_ref ? This needs to be investigated, and possibly, fixed

@smarie smarie added the enhancement New feature or request label Mar 31, 2021
@smarie smarie added new_feature and removed enhancement New feature or request labels Apr 30, 2021
@smarie
Copy link
Owner Author

smarie commented Jun 1, 2021

A first difficulty, even without adressing fixture_refs and cases, is to include parameter names in this indirect mechanism. Indeed, in pytest fixtures do not support several parameters so using indirect just requires the user to pass the fixture name.

With pytest-case since @fixture is compliant with multiple parametrize (multiple args), then indirect will require users to tell which arg is indirectly parametrized. In other words to pass the fixture name AND the argname(s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant