Skip to content

Commit 347ca1e

Browse files
author
Sylvain MARIE
committed
Fixed an issue where a lazy value would not be resolved. This happens when the "auto-simplify fixture" happens in @parametrize. Fixes #225
1 parent d84d8f3 commit 347ca1e

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

pytest_cases/fixture_core2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ def _create_param_fixture(fixtures_dest,
106106
raise ValueError("When auto_simplify=True the argvalue can not be a pytest.param")
107107

108108
# create the fixture - set its name so that the optional hook can read it easily
109-
@with_signature("%s()" % argname)
110-
def __param_fixture():
111-
return argvalue_to_return
109+
@with_signature("%s(request)" % argname)
110+
def __param_fixture(request):
111+
# do not forget to resolve the lazy values !
112+
return get_lazy_args(argvalue_to_return, request)
112113

113114
if debug:
114115
print("Creating unparametrized fixture %r returning %r" % (argname, argvalue_to_return))

pytest_cases/fixture_parametrize_plus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ def replace_paramfixture_with_values(kwargs): # noqa
10541054
return kwargs
10551055

10561056
if not isgeneratorfunction(test_func):
1057-
# normal test function with return statement
1057+
# normal test or fixture function with return statement
10581058
@wraps(test_func, new_sig=new_sig)
10591059
def wrapped_test_func(*args, **kwargs): # noqa
10601060
if kwargs.get(fixture_union_name, None) is NOT_USED:
@@ -1066,7 +1066,7 @@ def wrapped_test_func(*args, **kwargs): # noqa
10661066
return test_func(*args, **kwargs)
10671067

10681068
else:
1069-
# generator test function (with one or several yield statements)
1069+
# generator test or fixture function (with one or several yield statements)
10701070
@wraps(test_func, new_sig=new_sig)
10711071
def wrapped_test_func(*args, **kwargs): # noqa
10721072
if kwargs.get(fixture_union_name, None) is NOT_USED:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest_cases
2+
3+
4+
class MyCases:
5+
def case_x0(self, my_fixture):
6+
return 1
7+
8+
def case_x1(self):
9+
return 1
10+
11+
12+
@pytest_cases.parametrize_with_cases("c", cases=MyCases, debug=True)
13+
def case_y(c):
14+
return c * 2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest_cases
2+
3+
4+
@pytest_cases.fixture()
5+
def my_fixture():
6+
pass
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest_cases
2+
from pytest_cases.tests.cases.issues.issue_225.cases import *
3+
4+
5+
@pytest_cases.parametrize_with_cases("case_y", cases=case_y)
6+
def test_xy(case_y):
7+
assert case_y == 2

0 commit comments

Comments
 (0)