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

Support fixture_ref() in tuple of parameters #47

Closed
smarie opened this issue Jun 25, 2019 · 7 comments
Closed

Support fixture_ref() in tuple of parameters #47

smarie opened this issue Jun 25, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@smarie
Copy link
Owner

smarie commented Jun 25, 2019

No description provided.

@smarie smarie added the enhancement New feature or request label Jun 25, 2019
@smarie
Copy link
Owner Author

smarie commented Jul 3, 2019

It seems that if the fixture represents the whole tuple, it works, but it is not possible to use the reference for only one element of the tuple. To investigate, in order to see if this is really desirable.

@smarie
Copy link
Owner Author

smarie commented Jul 31, 2019

To add a more explicit description: the following does not work yet because the fixture reference is only used as a part of the parameters tuple:

import pytest
from pytest_cases import pytest_parametrize_plus, fixture_ref, pytest_fixture_plus

@pytest_fixture_plus
@pytest.mark.parametrize('val', ['b', 'c'])
def myfix(val):
    return val

@pytest_parametrize_plus('p,q', [('a', 1),
                                 (fixture_ref(myfix), 2)])
def test_prints(p, q):
    pass

def test_synthesis(module_results_dct):
    assert list(module_results_dct) == ['test_prints[test_prints_p_is_0-a-1]',
                                        'test_prints[test_prints_p_is_myfix-b-2]',
                                        'test_prints[test_prints_p_is_myfix-c-2]',
                                        ]

@yashtodi94
Copy link

Please add this feature. Would be of great use in testing different combinations in a complex function.

Also, the tests would be more reliable as one will then be able to do:

assert p == 'a' instead of assert p in ['a', 'b', 'c']

@smarie
Copy link
Owner Author

smarie commented Aug 1, 2019

Sorry my example code was wrong. I updated it to reflect what should actually be the behaviour (it uses pytest-harvest to get the synthesis). So your comment does not apply anymore, sorry: I removed the asserts you mention.

Can you please confirm that this is actually what you need ? I mean, for each parameter tuple containing at least a fixture_ref it will generate several parameter tuples by doing the cross-product of all fixture references' parameters. In that case there is only a single fixture reference so 2 parameters are generated:

(fixture_ref(myfix), 2) becomes ('b', 2), ('c', 2).

Note: this is not exactly how it works behind the scenes but the perceived result is equivalent, and it is easier to explain ;)

@yashtodi94
Copy link

Yes that is exactly what I am referring to. This will make the test code's syntax (and functionality) similar to how @pytest.mark.parametrize actually works. Will help in testing out multiple combinations of parameters. Also, saves a person from writing multiple tests just to test the combinations.

What do you think?

@smarie
Copy link
Owner Author

smarie commented Aug 1, 2019

perfect. I'll see what I can do.

@smarie smarie closed this as completed in afd8792 Aug 1, 2019
@smarie
Copy link
Owner Author

smarie commented Aug 1, 2019

Done in 1.11.0. But I warn you: the names become hard to follow ! :)

Let me know if it works for you.

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

No branches or pull requests

2 participants