diff --git a/src/pytest_bdd/scenario.py b/src/pytest_bdd/scenario.py index ac8844c5a..f8ecb88db 100644 --- a/src/pytest_bdd/scenario.py +++ b/src/pytest_bdd/scenario.py @@ -271,9 +271,6 @@ 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) @@ -281,6 +278,11 @@ def scenario_wrapper(request: FixtureRequest, _pytest_bdd_example: dict[str, str 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 @@ -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