Skip to content
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

Add zip join to combine fixtures #284

Open
tokarenko opened this issue Oct 16, 2022 · 1 comment
Open

Add zip join to combine fixtures #284

tokarenko opened this issue Oct 16, 2022 · 1 comment

Comments

@tokarenko
Copy link

Consider this issue as a feature request please. I suggest to add more flexibility to how parameters for tests are combined. In pytest tests are executed for each combination (cartesian product) of all parameters. I was glad to find fixture_union in pytest cases that introduces flexibility in combining fixture parameters for tests. I suggest to add further options to combine fixtures: zip join to combine fixture sets by position number in a set. This will allow to test actual and expected states determined for each test object in different fixtures:

@pytest_fixture_plus(params=[obj1, obj2, obj3])
def actual_state(request):
    return produce_actual_state(request.param)

@pytest_fixture_plus(params=[obj1, obj2, obj3])
def expected_state(request):
    return produce_expected_state(request.param)

fixture_zip("state", ['actual_state', 'expected_state'])

def test_with_zipped_fixture(state):
    assert state.actual_state == state.expected_state

@pytest_parametrize_plus_zip("actual, expected", ['actual_state', 'expected_state'])
def test_with_direct_parametrization(actual, expected):
    assert actual == expected
@smarie
Copy link
Owner

smarie commented Nov 25, 2022

Nice proposal @tokarenko !
It reminds me of #281 but seems more straightforward. Would you like to propose a PR, similar to the unpack_fixture function ? https://smarie.github.io/python-pytest-cases/api_reference/#unpack_fixture

Note that the implementation could construct a namedtuple so that both index-based access and named access (as in your example) works.

EDIT: sorry I rushed into this answer too fast. Developing such a feature might be quite tideous, as the internal engine does not support it and therefore would need to be adapted (the "fixture trees" and callspec generator). So maybe it is not worth doing until #170 is done (yet, there is no plan to tackle #170 in the near future :( ). For now the best workaround is probably to create a fixture parametrized with the zipped params, and then to unpack it using unpack_fixture, into two independent fixtures.

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

No branches or pull requests

2 participants