Using pytest fixture with parameter from mark

  fixtures, pytest, python-3.x, testing

I try to create a test case in pytest. I want to use parameterized fixtures to get parameters from the @pytest.mark.parametrize decorator and create more types of tests. My code looks right now:

@pytest.mark.parametrize( 
    "a",
    ["1", "2"],
    ids=["a:1", "a:2"]
)
@pytest.mark.parametrize(  # type: ignore
    "fixture_a",
    [{"b": 1}],
    ids=["b:1"],
    indirect=["fixture_a"],
)
def test_postgres_basic(fixture_a, a):
    ...

What do I want?

I want to send parameter a to fixture_a so fixture request.param wouldn’t be {"b": 1} but something like {"b":1, a: "1"} and {"b":1, a: "2"}. Is it possible in some easy way?

Thank you

Source: Python-3x Questions

LEAVE A COMMENT