Merge pull request #2819 from leezu/fix_kwargs_fixtures

Fix pytest.parametrize when argnames are specified as kwarg
This commit is contained in:
Ronny Pfannschmidt 2017-10-09 06:49:40 +02:00 committed by GitHub
commit 46e30435eb
3 changed files with 26 additions and 2 deletions

View File

@ -1037,8 +1037,13 @@ class FixtureManager:
if faclist:
fixturedef = faclist[-1]
if fixturedef.params is not None:
func_params = getattr(getattr(metafunc.function, 'parametrize', None), 'args', [[None]])
parametrize_func = getattr(metafunc.function, 'parametrize', None)
func_params = getattr(parametrize_func, 'args', [[None]])
func_kwargs = getattr(parametrize_func, 'kwargs', {})
# skip directly parametrized arguments
if "argnames" in func_kwargs:
argnames = parametrize_func.kwargs["argnames"]
else:
argnames = func_params[0]
if not isinstance(argnames, (tuple, list)):
argnames = [x.strip() for x in argnames.split(",") if x.strip()]

1
changelog/2819.bugfix Normal file
View File

@ -0,0 +1 @@
Fix issue with @pytest.parametrize if argnames was specified as kwarg.

View File

@ -342,6 +342,24 @@ def test_parametrized_collect_with_wrong_args(testdir):
])
def test_parametrized_with_kwargs(testdir):
"""Test collect parametrized func with wrong number of args."""
py_file = testdir.makepyfile("""
import pytest
@pytest.fixture(params=[1,2])
def a(request):
return request.param
@pytest.mark.parametrize(argnames='b', argvalues=[1, 2])
def test_func(a, b):
pass
""")
result = testdir.runpytest(py_file)
assert(result.ret == 0)
class TestFunctional(object):
def test_mark_per_function(self, testdir):