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.
If all the parameters to a fixture function have default values,
pytest.fixturehandles them appropriately butpytest_cases.fixturedoes not.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.partialor 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.