Repository navigation
pytest.mark.parametrize string-based parameter list doesn't handle single element tuples #719
Description
Activity
Original comment by Brianna Laugher (BitBucket: pfctdayelise, GitHub: pfctdayelise):
This looks closely related to #638.
- addedtype: bugproblem that needs to be addressedproblem that needs to be addressed
on Jun 15, 2015 @pfctdayelise is that one easy, its hard to tell off hand
- addedtopic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrize
on Jul 25, 2015 The current state:
- Single-arg parametrization means a list of values must be passed.
- Multi-arg parametrization means a list of value-tuples must be passed.
Unless I'm missing something, fixing this would create an ambiguity, as single-arg parametrization would take either values or tuples with one value each. It'd be no longer possible to pass tuples as parametrization values, i.e. it'd be no longer possible to replicate the current behavior of
scenarios = [("a",)]in the future.I think this issue should be closed -- the fix is to use
scenarios = ['a'].I think the OP means that these two tests should be equivalent:
import pytest scenarios = [('a',)] @pytest.mark.parametrize(("arg",), scenarios) def test_foo_1(arg): assert arg == 'a' @pytest.mark.parametrize("arg", scenarios) def test_foo_2(arg): assert arg == 'a'
test_foo.py::test_foo_1[a] FAILED test_foo.py::test_foo_2[arg0] PASSED ================================== FAILURES =================================== ________________________________ test_foo_1[a] ________________________________ arg = 'a' @pytest.mark.parametrize(("arg",), scenarios) def test_foo_1(arg): > assert arg == ('a',) E assert 'a' == ('a',) test_foo.py:7: AssertionError ===================== 1 failed, 1 passed in 0.02 seconds ======================When you use more than one argument, both tests work as expected:
import pytest scenarios = [('a', 'b')] @pytest.mark.parametrize(("arg","arg2"), scenarios) def test_bar_1(arg, arg2): assert arg == 'a' assert arg2 == 'b' @pytest.mark.parametrize("arg,arg2", scenarios) def test_bar_2(arg, arg2): assert arg == 'a' assert arg2 == 'b'
test_foo.py::test_bar_1[a-b] PASSED test_foo.py::test_bar_2[a-b] PASSEDI would expect both forms to work even if used with a single argument, so this seems like a bug to me... 😅
Reacted by Ashley ConnorI see, I misread the OP.
I would expect tuples for single arg string without the comma
I would expect tuples for single arg string without the comma
Could you elaborate your reasoning?
From the docs, it seems that passing
"arg"or("arg",)should be the same thing, that's why I feel it is a bug.think about a use-cases where you want to pass tuples of different arty to a single argument,
wouldn't it unpack them in a bad way ? - imho the structure of the definition should match the structure of the expression
the ',' writing is just a shortcut for the tuples - and just like tuples without a comma, its not a tuple
Could you post a code example of what you mean? I think it would be better to illustrate your point.
paramerize('a', [(1,), (1,2), (2,), ]) # a should never be 1 and never be 2Reacted by Curt J. SampsonI thought this issue was about passing tuples for the parameter NAMES, not the VALUES.
On 8 August 2015 18:44:46 CEST, Ronny Pfannschmidt notifications@github.com wrote:
paramerize('a', [(1,), (1,2), (2,), ]) # a should never be 1 and never be 2
Reply to this email directly or view it on GitHub:
#719 (comment)Sent from my phone. Please excuse my brevity.
@untitaker there is some detail logic involved wrt interaction between names and values, it'd take a while to dig this out properly, i cant promise it for this weekend
17 remaining items
- added 2 commits that reference this issue
on Jun 23, 2026 - added a commit that references this issue
on Jun 24, 2026 - added a commit that references this issue
on Jun 24, 2026 - added a commit that references this issue
on Jul 4, 2026 - added a commit that references this issue
on Jul 19, 2026 - added a commit that references this issue
on Jul 21, 2026 - added 2 commits that reference this issue
on Jul 22, 2026 - added a commit that references this issue
on Jul 29, 2026 - added a commit that references this issue
on Aug 17, 2026 - added a commit that references this issue
on Aug 31, 2026
Originally reported by: David Haney (BitBucket: david_haney, GitHub: david_haney)
When specifying a
@pytest.mark.parametrizeelement composed of a one-element tuple, I'm unable to use the string-based argument list, for example:arg ends up being the tuple instead of the first item in the tuple (as I would expected based on tuples with more than one item. I also tried:
but that also associated the entire tuple with arg instead of the first element. I reverted back to the older model of specifying the arguments as a tuple:
Finally I switched back to the older style of using a tuple to specify the parameter list:
This version worked. This seems to imply that there is either a bug/limitation in the new string-based parameter specification, or that there is still a use-case for the tuple-based parameter specification. It would be helpful if either the string-based implementation could be updated to handle this situation, or if the documentation could be updated to note when the tuple-based parameter specification is still needed.