Skip to content

Commit

Permalink
Merge pull request #746 from daara-s/fix-empty-usefixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
youtux authored Nov 30, 2024
2 parents 93e446e + a4bf843 commit 766fabe
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pytest_bdd/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,18 @@ def decorator(*args: Callable[P, T]) -> Callable[P, T]:
[fn] = args
func_args = get_args(fn)

# We need to tell pytest that the original function requires its fixtures,
# otherwise indirect fixtures would not work.
@pytest.mark.usefixtures(*func_args)
def scenario_wrapper(request: FixtureRequest, _pytest_bdd_example: dict[str, str]) -> Any:
__tracebackhide__ = True
scenario = templated_scenario.render(_pytest_bdd_example)
_execute_scenario(feature, scenario, request)
fixture_values = [request.getfixturevalue(arg) for arg in func_args]
return fn(*fixture_values)

if func_args:
# We need to tell pytest that the original function requires its fixtures,
# otherwise indirect fixtures would not work.
scenario_wrapper = pytest.mark.usefixtures(*func_args)(scenario_wrapper)

example_parametrizations = collect_example_parametrizations(templated_scenario)
if example_parametrizations is not None:
# Parametrize the scenario outlines
Expand All @@ -295,7 +297,7 @@ def scenario_wrapper(request: FixtureRequest, _pytest_bdd_example: dict[str, str
config.hook.pytest_bdd_apply_tag(tag=tag, function=scenario_wrapper)

scenario_wrapper.__doc__ = f"{feature_name}: {scenario_name}"
scenario_wrapper.__scenario__ = templated_scenario
scenario_wrapper.__scenario__ = templated_scenario # type: ignore[attr-defined]
return cast(Callable[P, T], scenario_wrapper)

return decorator
Expand Down

0 comments on commit 766fabe

Please sign in to comment.