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 John Towler
Joshua Bronson Joshua Bronson
Jurko Gospodnetić Jurko Gospodnetić
Justyna Janczyszyn
Katarzyna Jachim Katarzyna Jachim
Kale Kundert Kale Kundert
Kevin Cox 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``). * Allow passing a custom debugger class (e.g. ``--pdbcls=IPython.core.debugger:Pdb``).
Thanks to `@anntzer`_ for the PR. 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`_). * ``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 .. _#1664: https://github.com/pytest-dev/pytest/pull/1664
.. _#1684: https://github.com/pytest-dev/pytest/pull/1684 .. _#1684: https://github.com/pytest-dev/pytest/pull/1684
.. _#1723: https://github.com/pytest-dev/pytest/pull/1723 .. _#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 .. _#1749: https://github.com/pytest-dev/pytest/issues/1749
.. _@DRMacIver: https://github.com/DRMacIver .. _@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 .. _@tareqalayan: https://github.com/tareqalayan
.. _@taschini: https://github.com/taschini .. _@taschini: https://github.com/taschini
.. _@txomon: https://github.com/txomon .. _@txomon: https://github.com/txomon
.. _@tramwaj29: https://github.com/tramwaj29
2.9.2 2.9.2
===== =====

View File

@ -801,7 +801,13 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
valtypes = {} valtypes = {}
for arg in argnames: for arg in argnames:
if arg not in self.fixturenames: 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: if indirect is True:
valtypes = dict.fromkeys(argnames, "params") valtypes = dict.fromkeys(argnames, "params")
@ -811,7 +817,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
valtypes = dict.fromkeys(argnames, "funcargs") valtypes = dict.fromkeys(argnames, "funcargs")
for arg in indirect: for arg in indirect:
if arg not in argnames: 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)) self.function, arg))
valtypes[arg] = "params" valtypes[arg] = "params"
idfn = None idfn = None

View File

@ -394,7 +394,7 @@ class TestMetafunc:
""") """)
result = testdir.runpytest("--collect-only") result = testdir.runpytest("--collect-only")
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*uses no fixture 'y'*", "*uses no argument 'y'*",
]) ])
@pytest.mark.issue714 @pytest.mark.issue714
@ -417,8 +417,42 @@ class TestMetafunc:
"*uses no fixture 'y'*", "*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 @pytest.mark.issue714
def test_parametrize_indirect_uses_no_fixture_error_indirect_list(self, testdir): 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(""" testdir.makepyfile("""
import pytest import pytest
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
@ -431,7 +465,7 @@ class TestMetafunc:
""") """)
result = testdir.runpytest("--collect-only") result = testdir.runpytest("--collect-only")
result.stdout.fnmatch_lines([ result.stdout.fnmatch_lines([
"*uses no fixture 'y'*", "*uses no argument 'y'*",
]) ])
def test_addcalls_and_parametrize_indirect(self): def test_addcalls_and_parametrize_indirect(self):