Skip to content

Request the feature to apply indirect=True on particular argnames #714

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

Closed
pytestbot opened this issue Apr 8, 2015 · 3 comments
Closed
Labels
topic: parametrize related to @pytest.mark.parametrize type: enhancement new feature or API change, should be merged into features branch

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Alina Berdnikova (BitBucket: freakbelka, GitHub: freakbelka)


According to http://pytest.org/latest/parametrize.html#the-metafunc-object, if indirect=True it'll
pass each argvalue to its corresponding fixture function.

It would be great if there was a way to specify which arguments are to be passed as params to corresponding fixtures and which are to be passed directly to test -- for example, via explicitly listing names of those indirectly-parametrized fixtures.
If argument name is listed in indirect= list, but corresponding fixture is nowhere to be found, an error should be raised.
And if the argument not listed in the indirect= clause, it should be passed directly as a test parameter despite corresponding fixture being defined or not.

I'm expecting this code

#!python

@pytest.fixture(scope='function')
def bar(request):
    return 'little %s' % request.param


@pytest.fixture(scope='function')
def foo(request):
    return 'great %s' % request.param


@pytest.mark.parametrize('foo, bar, spam', [('ololol', 'lalala', 'cococo'),
                                            ('pewpew', 'pawpaw', 'pafpaf')], 
                                            indirect=('bar', 'foo'))
def test_one(foo, bar, spam):
    print foo, bar, spam

to output this:

#!python

============================= test session starts ==============================
platform darwin -- Python 2.7.5 -- py-1.4.26 -- pytest-2.6.4 -- /Users/freakbelka/.venv/bin/python
plugins: yadt
collecting ... collected 2 items

test_1.py::test_one[ololol-lalala-cococo] great ololol little lalala cococo
PASSED
test_1.py::test_one[pewpew-pawpaw-pafpaf] great pewpew little pawpaw pafpaf
PASSED
=========================== 2 passed in 2.59 seconds ===========================

@pytestbot pytestbot added the type: enhancement new feature or API change, should be merged into features branch label Jun 15, 2015
@martinpengellyphillips
Copy link

I encountered this limitation also. In general I want to be able to parametrize a test, but need to use a fixture result in the parametrization arguments so this proposal would help support that.

@pfctdayelise
Copy link
Contributor

Thanks for the clear explanation. One question - presumably the test names should actually be

test_1.py::test_one[great ololol-little lalala-cococo]
test_1.py::test_one[great pewpew-little pawpaw-pafpaf]

?

@pfctdayelise pfctdayelise added the topic: parametrize related to @pytest.mark.parametrize label Jul 26, 2015
@martinpengellyphillips
Copy link

@pfctdayelise That makes sense to me (though I'm not the OP).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: parametrize related to @pytest.mark.parametrize type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

4 participants