Skip to content

addcall does not allow binding of keyword args in parametrized test #42

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 May 1, 2011 · 3 comments
Closed
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: BitBucket: blep, GitHub: blep


When calling metafunc.addcall in pytest_generate_tests and providing keyword args with default value, addcall fails with a message such as:

bug\pytest_generator_kwargs.py:15: in pytest_generate_tests
>               metafunc.addcall( funcargs=kwargs )
C:\Python32\lib\site-packages\pytest-2.0.3-py3.2.egg\_pytest\python.py:550: in addcall
>                   pytest.fail("funcarg %r not used in this %r function." % (name, self.function))
E                   Failed: funcarg 'dbo_class' not used in this function.

Code example to reproduce the issue:

#!python

META_DBO_SCENARIOS = [
    dict( dbo_class=int,
          key_properties=['id'],
          value_properties=['content', 'name']
          )
    ]

def pytest_generate_tests(metafunc):
    if 'meta_dbo_iter' in metafunc.funcargnames:
        for scenario in META_DBO_SCENARIOS:
            kwargs = dict(meta_dbo_iter=None) # dummy parameter
            kwargs.update( scenario )
            metafunc.addcall( funcargs=kwargs )

def test_meta_dbo( meta_dbo_iter, dbo_class=None,
                   key_names=(), value_names=(),
                   auto_id=None ):
    """Checks the properties meta-data of a dbo class.
    """
    # ...

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


it's true that only arguments without defaults are currently considered as "funcargs". how comes you need to have such a signature for your test functions? It's not impossible to extend the mechanism but i'd like to see the need.

@pytestbot
Copy link
Contributor Author

Original comment by Anonymous:


It is frequent for data driven tests to have a few mandatory parameters and some optional parameters. Keyword parameters provide a convenient way to provide default value for optional parameters. This makes it easy to add a new optional parameter to handle the need of a few new specific test without impacting existing tests.

I currently work around this by forwarding to a nested function as in the example below. dbo_class is the only required parameters, though the code below does not express this.

{{{
#!python

def test_meta_dbo( data ):
def do_test( dbo_class=None, key_properties=(), value_properties=(), auto_id=None ):
pass
do_test( **data )

}}}

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


i think this has been fixed long ago (and you now call metafunc.parametrize()).

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant