Skip to content

Create a parametrized fixture #8062

Closed Answered by The-Compiler
Gadzillion asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think you can do this directly from a fixture. You could either use parametrize and some helper function:

import pytest

LIST_1 = [1, 3]
LIST_2 = [1, 2]

def gen_params(elems1, elems2):
    return list(zip(elems1, elems2))

@pytest.mark.parametrize('tester', gen_params(LIST_1, LIST_2))
def test_button(tester):
    assert False, tester

or use a custom mark and the pytest_generate_tests hook with Metafunc.parametrize to implement custom parametrization.

If you can say more about what your actual use-case is, it might be possible to suggest a simpler/better alternative as well.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Gadzillion
Comment options

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