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

Fix pytest.parametrize when argnames are specified as kwarg #2819

Merged
merged 4 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions _pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,9 +1037,14 @@ def pytest_generate_tests(self, metafunc):
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
argnames = func_params[0]
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()]
if argname not in func_params and argname not in argnames:
Expand Down
1 change: 1 addition & 0 deletions changelog/2819.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue with @pytest.parametrize if argnames was specified as kwarg.
18 changes: 18 additions & 0 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,24 @@ def test_func(foo, bar):
])


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):
Expand Down