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

clarify docs on Multiple Calls to metafunc.parametrize #1548

Closed
astraw38 opened this issue May 4, 2016 · 2 comments · Fixed by #2766
Closed

clarify docs on Multiple Calls to metafunc.parametrize #1548

astraw38 opened this issue May 4, 2016 · 2 comments · Fixed by #2766
Labels
good first issue easy issue that is friendly to new contributor status: help wanted developers would like help from experts on this topic type: docs documentation improvement, missing or needing clarification

Comments

@astraw38
Copy link

astraw38 commented May 4, 2016

The docs say "Add new invocations to the underlying test function using the list of argvalues for the given argnames."; which would imply that you could call it multiple times to add more invocations.

It's a relatively minor issue, since you can store off into a final parametrization list then call it once later, but it should probably be noted in the docs.

Simple test of the form:

# in conftest.py
def pytest_generate_tests(metafunc):
    metafunc.parametrize("arg1",
                         [1, 2],
                         scope='function')
    metafunc.parametrize("arg1",
                         [3, 4],
                         scope='function')

# in test_file.py:
def test_me(self,  arg1):
    assert arg1

The output of the example above:

==================================== ERRORS ====================================
_____________________ ERROR collecting test_gen_classes.py _____________________
../../../.PyCharm50/config/scratches/pytesting/conftest.py:16: in pytest_generate_tests
    scope='function')
/usr/local/lib/python2.7/site-packages/_pytest/python.py:1029: in parametrize
    param_index)
/usr/local/lib/python2.7/site-packages/_pytest/python.py:869: in setmulti
    self._checkargnotcontained(arg)
/usr/local/lib/python2.7/site-packages/_pytest/python.py:852: in _checkargnotcontained
    raise ValueError("duplicate %r" %(arg,))
E   ValueError: duplicate 'arg1'
=========================== 1 error in 0.19 seconds ============================
@RonnyPfannschmidt
Copy link
Member

this works as designed, per parameter name set you get one call (else things get really tricky)

@astraw38
Copy link
Author

astraw38 commented May 4, 2016

I figured as much, but it should be noted in the docs to remove ambiguity.

@RonnyPfannschmidt RonnyPfannschmidt added status: help wanted developers would like help from experts on this topic type: docs documentation improvement, missing or needing clarification good first issue easy issue that is friendly to new contributor labels May 4, 2016
@RonnyPfannschmidt RonnyPfannschmidt changed the title Multiple Calls to metafunc.parametrize fail clarify docs on Multiple Calls to metafunc.parametrize May 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor status: help wanted developers would like help from experts on this topic type: docs documentation improvement, missing or needing clarification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants