Skip to content

Commit f26fa5a

Browse files
committed
changed error message for unused parametrize name
1 parent ae07985 commit f26fa5a

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

_pytest/python.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,13 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
801801
valtypes = {}
802802
for arg in argnames:
803803
if arg not in self.fixturenames:
804-
raise ValueError("%r uses no fixture %r" %(self.function, arg))
804+
if isinstance(indirect, (tuple, list)):
805+
name = 'fixture' if arg in indirect else 'argument'
806+
else:
807+
name = 'fixture' if indirect is True else 'argument'
808+
raise ValueError(
809+
"%r uses no %s %r" % (
810+
self.function, name, arg))
805811

806812
if indirect is True:
807813
valtypes = dict.fromkeys(argnames, "params")
@@ -811,7 +817,7 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
811817
valtypes = dict.fromkeys(argnames, "funcargs")
812818
for arg in indirect:
813819
if arg not in argnames:
814-
raise ValueError("indirect given to %r: fixture %r doesn't exist" %(
820+
raise ValueError("indirect given to %r: fixture %r doesn't exist" % (
815821
self.function, arg))
816822
valtypes[arg] = "params"
817823
idfn = None

testing/python/metafunc.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def test_simple(x):
394394
""")
395395
result = testdir.runpytest("--collect-only")
396396
result.stdout.fnmatch_lines([
397-
"*uses no fixture 'y'*",
397+
"*uses no argument 'y'*",
398398
])
399399

400400
@pytest.mark.issue714
@@ -425,7 +425,7 @@ def test_parametrize_indirect_uses_no_fixture_error_indirect_list(self, testdir)
425425
def x(request):
426426
return request.param * 3
427427
428-
@pytest.mark.parametrize('x, y', [('a', 'b')], indirect=['x'])
428+
@pytest.mark.parametrize('x, y', [('a', 'b')], indirect=['y'])
429429
def test_simple(x):
430430
assert len(x) == 3
431431
""")
@@ -434,6 +434,23 @@ def test_simple(x):
434434
"*uses no fixture 'y'*",
435435
])
436436

437+
@pytest.mark.issue714
438+
def test_parametrize_argument_not_in_indirect_list(self, testdir):
439+
testdir.makepyfile("""
440+
import pytest
441+
@pytest.fixture(scope='function')
442+
def x(request):
443+
return request.param * 3
444+
445+
@pytest.mark.parametrize('x, y', [('a', 'b')], indirect=['x'])
446+
def test_simple(x):
447+
assert len(x) == 3
448+
""")
449+
result = testdir.runpytest("--collect-only")
450+
result.stdout.fnmatch_lines([
451+
"*uses no argument 'y'*",
452+
])
453+
437454
def test_addcalls_and_parametrize_indirect(self):
438455
def func(x, y): pass
439456
metafunc = self.Metafunc(func)

0 commit comments

Comments
 (0)