Skip to content

clarify docs on Multiple Calls to metafunc.parametrize #1548

@astraw38

Description

@astraw38

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 ============================

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributorstatus: help wanteddevelopers would like help from experts on this topictype: docsdocumentation improvement, missing or needing clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions