Merge pull request #1757 from tramwaj29/improved-message-when-not-using-parametrized-variable

Improved message when not using parametrized variable
This commit is contained in:
Bruno Oliveira 2016-07-24 13:02:03 -03:00 committed by GitHub
commit a24146dd3c
4 changed files with 50 additions and 5 deletions

View File

@ -65,6 +65,7 @@ Javier Domingo Cansino
John Towler
Joshua Bronson
Jurko Gospodnetić
Justyna Janczyszyn
Katarzyna Jachim
Kale Kundert
Kevin Cox

View File

@ -149,7 +149,6 @@ time or change existing behaviors in order to make them less surprising/more use
* Allow passing a custom debugger class (e.g. ``--pdbcls=IPython.core.debugger:Pdb``).
Thanks to `@anntzer`_ for the PR.
*
*
@ -237,6 +236,9 @@ time or change existing behaviors in order to make them less surprising/more use
* ``optparse`` backward compatibility supports float/complex types (`#457`_).
* Better message in case of not using parametrized variable (see `#1539`_).
Thanks to `@tramwaj29`_ for the PR.
*
*
@ -318,6 +320,7 @@ time or change existing behaviors in order to make them less surprising/more use
.. _#1664: https://github.com/pytest-dev/pytest/pull/1664
.. _#1684: https://github.com/pytest-dev/pytest/pull/1684
.. _#1723: https://github.com/pytest-dev/pytest/pull/1723
.. _#1539: https://github.com/pytest-dev/pytest/issues/1539
.. _#1749: https://github.com/pytest-dev/pytest/issues/1749
.. _@DRMacIver: https://github.com/DRMacIver
@ -351,6 +354,7 @@ time or change existing behaviors in order to make them less surprising/more use
.. _@tareqalayan: https://github.com/tareqalayan
.. _@taschini: https://github.com/taschini
.. _@txomon: https://github.com/txomon
.. _@tramwaj29: https://github.com/tramwaj29
2.9.2
=====

View File

@ -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 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

View File

@ -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
@ -417,8 +417,42 @@ class TestMetafunc:
"*uses no fixture 'y'*",
])
@pytest.mark.issue714
def test_parametrize_indirect_uses_no_fixture_error_indirect_string(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='y')
def test_simple(x):
assert len(x) == 3
""")
result = testdir.runpytest("--collect-only")
result.stdout.fnmatch_lines([
"*uses no fixture 'y'*",
])
@pytest.mark.issue714
def test_parametrize_indirect_uses_no_fixture_error_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=['y'])
def test_simple(x):
assert len(x) == 3
""")
result = testdir.runpytest("--collect-only")
result.stdout.fnmatch_lines([
"*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')
@ -431,7 +465,7 @@ class TestMetafunc:
""")
result = testdir.runpytest("--collect-only")
result.stdout.fnmatch_lines([
"*uses no fixture 'y'*",
"*uses no argument 'y'*",
])
def test_addcalls_and_parametrize_indirect(self):