Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Test len with 2 parameters

We can use 2 parameters in the parametrization.

import pytest

@pytest.mark.parametrize("text", ["Foo", "Bar", "🐍🐪🦀"])
def test_cases_3(text):
    assert len(text) == 3

@pytest.mark.parametrize("text", ["apple", "banan"])
def test_cases_5(text):
    assert len(text) == 5


@pytest.mark.parametrize("text,length", [
    ("Foo", 3),
    ("Bar", 3),
    ("🐍🐪🦀", 3),
    ("apple", 5),
    ("banana", 6),
    ])
def test_cases(text, length):
    assert len(text) == length

Output:

..........                                                               [100%]
10 passed in 0.07s