Skip to content

Surprising parametrized fixtures order #5054

@smarie

Description

@smarie

Hi,

The example below seems to always lead to the same tests execution order, in both pytest 2, 3, and 4. However the order is counter intuitive:

import pytest

@pytest.fixture(params=[(1, 2), (3, 4)], ids=str)
def arg1_arg2_root(request):
    return request.param

@pytest.fixture
def arg1(arg1_arg2_root):
    return arg1_arg2_root[0]

@pytest.fixture
def arg2(arg1_arg2_root):
    return arg1_arg2_root[1]

@pytest.fixture(params=[5, 6])
def arg3(request):
    return request.param

def test_order(arg1, arg2, arg3):
    pass

leads to

<..>::test_order[5-(1, 2)] 
<..>::test_order[5-(3, 4)] 
<..>::test_order[6-(1, 2)] 
<..>::test_order[6-(3, 4)] 

However it seems counter-intuitive to me. Indeed all the fixtures are function-scopes fixtures, and the function uses arg1 (so, arg1_arg2_root) first, then arg2 (same root), then arg3. I would therefore expect:

<..>::test_order[(1, 2)-5] 
<..>::test_order[(1, 2)-6] 
<..>::test_order[(3, 4)-5] 
<..>::test_order[(3, 4)-6] 

Do you agree ? If so that's maybe a bug happening when the fixture closure is computed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions