From f26fa5a441022da8a86926bef7d9aebefa6c832b Mon Sep 17 00:00:00 2001 From: JJ Date: Sat, 23 Jul 2016 16:49:20 +0200 Subject: [PATCH 1/4] changed error message for unused parametrize name --- _pytest/python.py | 10 ++++++++-- testing/python/metafunc.py | 21 +++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/_pytest/python.py b/_pytest/python.py index 37151d907..546269896 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 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 diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index ac8e512d4..1e18dd35d 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 @@ -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) From 36317190509fc624dbcb1b0b32eeca86f8f6fe40 Mon Sep 17 00:00:00 2001 From: JJ Date: Sat, 23 Jul 2016 16:51:55 +0200 Subject: [PATCH 2/4] added myself to authors --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 1f842780f..3f37e5b81 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 From bbc7f3a6314691a48d71b0dd282f31e5ea1b4f54 Mon Sep 17 00:00:00 2001 From: JJ Date: Sat, 23 Jul 2016 16:57:49 +0200 Subject: [PATCH 3/4] updated changelog, resolve #1539 --- CHANGELOG.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 522d63aa2..647612039 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -146,7 +146,8 @@ time or change existing behaviors in order to make them less surprising/more use Thanks to `@anntzer`_ for the PR. -* +* Better message in case of not using parametrized variable (see `#1539`_). + Thanks to `@tramwaj29`_ for the PR. * @@ -314,6 +315,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 .. _@DRMacIver: https://github.com/DRMacIver .. _@RedBeardCode: https://github.com/RedBeardCode @@ -345,6 +347,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 ===== From d000f2536ac87ea5c922a46f5d58895f34ac751c Mon Sep 17 00:00:00 2001 From: JJ Date: Sun, 24 Jul 2016 10:47:06 +0200 Subject: [PATCH 4/4] added a test for when the indirect is just a string --- CHANGELOG.rst | 7 ++++--- _pytest/python.py | 2 +- testing/python/metafunc.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 647612039..41e63606c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -145,9 +145,7 @@ 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. - -* Better message in case of not using parametrized variable (see `#1539`_). - Thanks to `@tramwaj29`_ for the PR. +* * @@ -234,6 +232,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. + * * diff --git a/_pytest/python.py b/_pytest/python.py index 546269896..8db0d9960 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -804,7 +804,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr): if isinstance(indirect, (tuple, list)): name = 'fixture' if arg in indirect else 'argument' else: - name = 'fixture' if indirect is True else 'argument' + name = 'fixture' if indirect else 'argument' raise ValueError( "%r uses no %s %r" % ( self.function, name, arg)) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 1e18dd35d..e55761896 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -417,6 +417,23 @@ 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("""