From d000f2536ac87ea5c922a46f5d58895f34ac751c Mon Sep 17 00:00:00 2001 From: JJ Date: Sun, 24 Jul 2016 10:47:06 +0200 Subject: [PATCH] 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("""