Skip to content

fixture gets confused by functions with all default parameters #279

@vyasr

Description

@vyasr

If all the parameters to a fixture function have default values, pytest.fixture handles them appropriately but pytest_cases.fixture does not.

import pytest
import pytest_cases

# This works
@pytest.fixture
def fix(x=1):
    return 2 * x

# This works again
@pytest_cases.fixture
def fix2(request, x=1):
    return 2 * x

# This fails
@pytest_cases.fixture
def fix3(x=1):
    return 2 * x

My use case is the dynamic generation of fixtures in a loop and using default parameters as a way to avoid late binding issues. I could of course make use of functools.partial or in general find some other way to introduce another stack frame to avoid the value changing within the closure where the function is defined, and for the moment just tossing in the unused request fixture also solves my problem, so this isn't a blocker but certainly surprising behavior.

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