diff --git a/AUTHORS b/AUTHORS index 2cdf587c0..4320d74ff 100644 --- a/AUTHORS +++ b/AUTHORS @@ -65,6 +65,7 @@ Javier Domingo Cansino John Towler Joshua Bronson Jurko Gospodnetić +Justyna Janczyszyn Katarzyna Jachim Kale Kundert Kevin Cox diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 63b574e52..31e0a457b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ===== diff --git a/_pytest/python.py b/_pytest/python.py index 37151d907..8db0d9960 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -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 diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index ac8e512d4..e55761896 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -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):