File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,11 @@ def _execute_step_function(
162
162
raise
163
163
164
164
if context .target_fixture is not None :
165
- inject_fixture (request , context .target_fixture , return_value )
165
+ target_fixture_tokens = [token for token in context .target_fixture .split (',' ) if token ]
166
+ return_values = (return_value ,) if not isinstance (return_value , tuple ) else return_value
167
+ assert len (target_fixture_tokens ) == len (return_values ), f"Return value count: { len (return_values )} are not matching target_fixture count: { len (target_fixture_tokens )} "
168
+ for token , value in zip (target_fixture_tokens , return_values ):
169
+ inject_fixture (request , token , value )
166
170
167
171
request .config .hook .pytest_bdd_after_step (** kw )
168
172
Original file line number Diff line number Diff line change @@ -38,3 +38,42 @@ def _(foo):
38
38
)
39
39
result = pytester .runpytest ()
40
40
result .assert_outcomes (passed = 1 )
41
+
42
+
43
+ def test_given_injection_multiple (pytester ):
44
+ pytester .makefile (
45
+ ".feature" ,
46
+ given = textwrap .dedent (
47
+ """\
48
+ Feature: Given
49
+ Scenario: Test given fixture injection
50
+ Given I have injecting given
51
+ Then foo should be "injected foo"
52
+ """
53
+ ),
54
+ )
55
+ pytester .makepyfile (
56
+ textwrap .dedent (
57
+ """\
58
+ import pytest
59
+ from pytest_bdd import given, then, scenario
60
+
61
+ @scenario("given.feature", "Test given fixture injection")
62
+ def test_given():
63
+ pass
64
+
65
+ @given("I have injecting given", target_fixture="foo,bar")
66
+ def _():
67
+ return "injected foo", "injected bar"
68
+
69
+
70
+ @then('foo should be "injected foo"')
71
+ def _(foo, bar):
72
+ assert foo == "injected foo"
73
+ assert bar == "injected bar"
74
+
75
+ """
76
+ )
77
+ )
78
+ result = pytester .runpytest ()
79
+ result .assert_outcomes (passed = 1 )
You can’t perform that action at this time.
0 commit comments