changed error message for unused parametrize name
This commit is contained in:
parent
ae0798522f
commit
f26fa5a441
|
@ -801,7 +801,13 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
|
|||
valtypes = {}
|
||||
for arg in argnames:
|
||||
if arg not in self.fixturenames:
|
||||
raise ValueError("%r uses no fixture %r" %(self.function, arg))
|
||||
if isinstance(indirect, (tuple, list)):
|
||||
name = 'fixture' if arg in indirect else 'argument'
|
||||
else:
|
||||
name = 'fixture' if indirect is True else 'argument'
|
||||
raise ValueError(
|
||||
"%r uses no %s %r" % (
|
||||
self.function, name, arg))
|
||||
|
||||
if indirect is True:
|
||||
valtypes = dict.fromkeys(argnames, "params")
|
||||
|
@ -811,7 +817,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
|
|||
valtypes = dict.fromkeys(argnames, "funcargs")
|
||||
for arg in indirect:
|
||||
if arg not in argnames:
|
||||
raise ValueError("indirect given to %r: fixture %r doesn't exist" %(
|
||||
raise ValueError("indirect given to %r: fixture %r doesn't exist" % (
|
||||
self.function, arg))
|
||||
valtypes[arg] = "params"
|
||||
idfn = None
|
||||
|
|
|
@ -394,7 +394,7 @@ class TestMetafunc:
|
|||
""")
|
||||
result = testdir.runpytest("--collect-only")
|
||||
result.stdout.fnmatch_lines([
|
||||
"*uses no fixture 'y'*",
|
||||
"*uses no argument 'y'*",
|
||||
])
|
||||
|
||||
@pytest.mark.issue714
|
||||
|
@ -425,7 +425,7 @@ class TestMetafunc:
|
|||
def x(request):
|
||||
return request.param * 3
|
||||
|
||||
@pytest.mark.parametrize('x, y', [('a', 'b')], indirect=['x'])
|
||||
@pytest.mark.parametrize('x, y', [('a', 'b')], indirect=['y'])
|
||||
def test_simple(x):
|
||||
assert len(x) == 3
|
||||
""")
|
||||
|
@ -434,6 +434,23 @@ class TestMetafunc:
|
|||
"*uses no fixture 'y'*",
|
||||
])
|
||||
|
||||
@pytest.mark.issue714
|
||||
def test_parametrize_argument_not_in_indirect_list(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
import pytest
|
||||
@pytest.fixture(scope='function')
|
||||
def x(request):
|
||||
return request.param * 3
|
||||
|
||||
@pytest.mark.parametrize('x, y', [('a', 'b')], indirect=['x'])
|
||||
def test_simple(x):
|
||||
assert len(x) == 3
|
||||
""")
|
||||
result = testdir.runpytest("--collect-only")
|
||||
result.stdout.fnmatch_lines([
|
||||
"*uses no argument 'y'*",
|
||||
])
|
||||
|
||||
def test_addcalls_and_parametrize_indirect(self):
|
||||
def func(x, y): pass
|
||||
metafunc = self.Metafunc(func)
|
||||
|
|
Loading…
Reference in New Issue