Skip to content

Commit

Permalink
Issue pytest-dev#2383 - Show the correct error message when collect "…
Browse files Browse the repository at this point in the history
…parametrize" func with wrong args and add test for this case.
  • Loading branch information
robin0371 committed Apr 29, 2017
1 parent d7d2249 commit 60b8339
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@ Tyler Goodlet
Vasily Kuznetsov
Victor Uriarte
Vidar T. Fauske
Vitaly Lashmanov
Wouter van Ackooy
Xuecong Liao
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* Allow collecting files with any file extension as Python modules (`#2369`_).
Thanks `@Kodiologist`_ for the PR.

* Show the correct error message when collect "parametrize" func with wrong args (`#2383`_).
Thanks `@The-Compiler`_ for the report and `@robin0371`_ for the PR.

*

*
Expand All @@ -27,12 +30,14 @@
.. _@fabioz: https://github.com/fabioz
.. _@metasyn: https://github.com/metasyn
.. _@Kodiologist: https://github.com/Kodiologist
.. _@robin0371: https://github.com/robin0371


.. _#1937: https://github.com/pytest-dev/pytest/issues/1937
.. _#2276: https://github.com/pytest-dev/pytest/issues/2276
.. _#2336: https://github.com/pytest-dev/pytest/issues/2336
.. _#2369: https://github.com/pytest-dev/pytest/issues/2369
.. _#2383: https://github.com/pytest-dev/pytest/issues/2383


3.0.7 (2017-03-14)
Expand Down
6 changes: 5 additions & 1 deletion _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,11 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
for callspec in self._calls or [CallSpec2(self)]:
elements = zip(ids, argvalues, newkeywords, count())
for a_id, valset, keywords, param_index in elements:
assert len(valset) == len(argnames)
if len(valset) != len(argnames):
raise ValueError(
'In "parametrize" the number of values ({0}) must be '
'equal to the number of names ({1})'.format(
valset, argnames))
newcallspec = callspec.copy(self)
newcallspec.setmulti(valtypes, argnames, valset, a_id,
keywords, scopenum, param_index)
Expand Down
17 changes: 17 additions & 0 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,23 @@ def test_func(arg):
rec.assertoutcome(passed=3)


def test_parametrized_collect_with_wrong_args(testdir):
"""Test collect parametrized func with wrong number of args."""
py_file = testdir.makepyfile("""
import pytest
@pytest.mark.parametrize('foo, bar', [(1, 2, 3)])
def test_func(foo, bar):
pass
""")

result = testdir.runpytest(py_file)
result.stdout.fnmatch_lines([
'E ValueError: In "parametrize" the number of values ((1, 2, 3)) '
'must be equal to the number of names ([\'foo\', \'bar\'])'
])


class TestFunctional:

def test_mark_per_function(self, testdir):
Expand Down

0 comments on commit 60b8339

Please sign in to comment.