lundi 7 janvier 2019

Using a fixture inside pytest.mark.parametrize

Say I have a test function that takes a parametrize record as a dict, where one of its values is a fixture which is already defined.

For example, we have a fixture:

@pytest.fixture
def a_value():
    return "some_value"

And the test function:

@pytest.mark.parametrize("record", [{"a": a_value, "other": "other_value"}])
def test_record(record):
    do_something(record)

Now, I know that this can be solved by passing the fixture to the test function and updating the record accordingly, like:

@pytest.mark.parametrize("record", [{"other": "other_value"}])
def test_record(a_value, record):
    record["a"] = a_value
    do_something(record)

But I was wondering if there is a way of doing this without this "workaround", when i have many fixtures that are already defined and I just want to use them in each parametrized record I pass to the function.

I have already checked this question, although it doesn't seem to fit to my case exactly. Couldn't find a correct use from the answers there.

Aucun commentaire:

Enregistrer un commentaire