Create a parametrized fixture #8062
-
I want to create a parametrized fixture that gets args (for example two lists) from a test, performs some actions on it, return one list (based on two given), and uses one value at a time from the list (code below doesn't work, but it shows my idea):
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 If you can say more about what your actual use-case is, it might be possible to suggest a simpler/better alternative as well. |
Beta Was this translation helpful? Give feedback.
I don't think you can do this directly from a fixture. You could either use parametrize and some helper function:
or use a custom mark and the
pytest_generate_tests
hook withMetafunc.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.