Skip to content

Commit bfd2563

Browse files
authored
Merge pull request #2386 from robin0371/show-correct-msg
Issue #2383 - AssertionError with wrong number of parametrize arguments
2 parents d7d2249 + 60b8339 commit bfd2563

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,6 @@ Tyler Goodlet
151151
Vasily Kuznetsov
152152
Victor Uriarte
153153
Vidar T. Fauske
154+
Vitaly Lashmanov
154155
Wouter van Ackooy
155156
Xuecong Liao

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* Allow collecting files with any file extension as Python modules (`#2369`_).
1616
Thanks `@Kodiologist`_ for the PR.
1717

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

2023
*
@@ -27,12 +30,14 @@
2730
.. _@fabioz: https://github.com/fabioz
2831
.. _@metasyn: https://github.com/metasyn
2932
.. _@Kodiologist: https://github.com/Kodiologist
33+
.. _@robin0371: https://github.com/robin0371
3034

3135

3236
.. _#1937: https://github.com/pytest-dev/pytest/issues/1937
3337
.. _#2276: https://github.com/pytest-dev/pytest/issues/2276
3438
.. _#2336: https://github.com/pytest-dev/pytest/issues/2336
3539
.. _#2369: https://github.com/pytest-dev/pytest/issues/2369
40+
.. _#2383: https://github.com/pytest-dev/pytest/issues/2383
3641

3742

3843
3.0.7 (2017-03-14)

_pytest/python.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,11 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None,
853853
for callspec in self._calls or [CallSpec2(self)]:
854854
elements = zip(ids, argvalues, newkeywords, count())
855855
for a_id, valset, keywords, param_index in elements:
856-
assert len(valset) == len(argnames)
856+
if len(valset) != len(argnames):
857+
raise ValueError(
858+
'In "parametrize" the number of values ({0}) must be '
859+
'equal to the number of names ({1})'.format(
860+
valset, argnames))
857861
newcallspec = callspec.copy(self)
858862
newcallspec.setmulti(valtypes, argnames, valset, a_id,
859863
keywords, scopenum, param_index)

testing/test_mark.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,23 @@ def test_func(arg):
301301
rec.assertoutcome(passed=3)
302302

303303

304+
def test_parametrized_collect_with_wrong_args(testdir):
305+
"""Test collect parametrized func with wrong number of args."""
306+
py_file = testdir.makepyfile("""
307+
import pytest
308+
309+
@pytest.mark.parametrize('foo, bar', [(1, 2, 3)])
310+
def test_func(foo, bar):
311+
pass
312+
""")
313+
314+
result = testdir.runpytest(py_file)
315+
result.stdout.fnmatch_lines([
316+
'E ValueError: In "parametrize" the number of values ((1, 2, 3)) '
317+
'must be equal to the number of names ([\'foo\', \'bar\'])'
318+
])
319+
320+
304321
class TestFunctional:
305322

306323
def test_mark_per_function(self, testdir):

0 commit comments

Comments
 (0)