Skip to content

Using a @fixture returning a list of params to parametrize a test #235

@DahanDv

Description

@DahanDv

Hey fellow maintainers, I'll be glad to have your guidance..

I'm trying to use pytest cases to parameterize a test with a list of tuples(str, iterable) that is yielded from a (pytest-cases)@fixture, but something isn't working for me.

It goes like the following:

# We have a native @pytest.fixture that yield a value
@pytest.fixture
def give_some_val():
    return val

# Then I use this val in a pytest-cases @fixture so I can use it to parameterized my test later
@fixture
def prepare_params(give_some_val):
    val_to_list_of_tuples = data_manipulation(give_some_val)
    yield val_to_list_of_tuples

To clarify, the yielded value looks something like:
[('event_name': {'uuid1','uuid2'}), ('another_event_name': {'uuid3', 'uuid4'}),(..),....]
again, list of tuples(string, set) .

when I try to implement this (either with @paytest.mark.parametrize or via @parametrize) like so:

@parametrize(argsnames="event,data", argvals="prepare_params"
def test(event, data, another_native_pytest_fixture):
      assert make_sense(data, another_native_pytest_fixture), f"{event} failed"`

it seems like pytest can't create more tests nodes..
instead, it creates just one test node and it fails to recognize the structure of ("name1,name2", list_of_tuples_with_2_elements)
instead it treats every element in the list as a single param.
I mean:
event = ('event_name': {'uuid1','uuid2'})
data = ('another_event_name': {'uuid3', 'uuid4'})

and that's it. no more test nodes.

I've gone through the docs multiple times but I can't find the answer.
Highly appreciate your time if you got so far!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions