diff --git a/src/pytest_bdd/scenario.py b/src/pytest_bdd/scenario.py index 864346ce..1941b9cd 100644 --- a/src/pytest_bdd/scenario.py +++ b/src/pytest_bdd/scenario.py @@ -162,9 +162,11 @@ def _execute_step_function( raise if context.target_fixture is not None: - target_fixture_tokens = [token for token in context.target_fixture.split(',') if token] + target_fixture_tokens = [token for token in context.target_fixture.split(",") if token] return_values = (return_value,) if not isinstance(return_value, tuple) else return_value - 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)}" + 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)}" for token, value in zip(target_fixture_tokens, return_values): inject_fixture(request, token, value) diff --git a/tests/steps/test_given.py b/tests/steps/test_given.py index caa890b9..c9ce83d5 100644 --- a/tests/steps/test_given.py +++ b/tests/steps/test_given.py @@ -2,7 +2,7 @@ import textwrap -def test_given_injection(pytester): +def test_given_injection_single_value(pytester): pytester.makefile( ".feature", given=textwrap.dedent( @@ -40,15 +40,15 @@ def _(foo): result.assert_outcomes(passed=1) -def test_given_injection_multiple(pytester): +def test_given_injection_multiple_values(pytester): pytester.makefile( ".feature", given=textwrap.dedent( """\ Feature: Given Scenario: Test given fixture injection - Given I have injecting given - Then foo should be "injected foo" + Given I have injecting given values + Then values should be received """ ), ) @@ -62,18 +62,19 @@ def test_given_injection_multiple(pytester): def test_given(): pass - @given("I have injecting given", target_fixture="foo,bar") + @given("I have injecting given values", target_fixture="foo,city,numbers") def _(): - return "injected foo", "injected bar" + return ("injected foo", {"city": ["Boston", "Houston"]}, [10,20,30],) - @then('foo should be "injected foo"') - def _(foo, bar): + @then("values should be received") + def _(foo, city, numbers): assert foo == "injected foo" - assert bar == "injected bar" + assert city == {"city": ["Boston", "Houston"]} + assert numbers == [10,20,30] """ ) ) result = pytester.runpytest() - result.assert_outcomes(passed=1) \ No newline at end of file + result.assert_outcomes(passed=1)