Skip to content

how to use a loop with pytest.mark.parametrize() ? #9822

Answered by nicoddemus
maphew asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @maphew,

The answer is to build the list of possible pytest.param values and pass that on to pytest.mark.parametrize:

params = [
    pytest.param(x, {
        "stdout": responses[x][0],
        "stderr": responses[x][1],
    })
    for x in utils
]    

@pytest.mark.parametrize("input,want", params)
def test_program(input, want):
    ...

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@maphew
Comment options

@parkitny
Comment options

Answer selected by maphew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants