Skip to content

Commit 766fabe

Browse files
authored
Merge pull request #746 from daara-s/fix-empty-usefixtures
2 parents 93e446e + a4bf843 commit 766fabe

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/pytest_bdd/scenario.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,18 @@ def decorator(*args: Callable[P, T]) -> Callable[P, T]:
271271
[fn] = args
272272
func_args = get_args(fn)
273273

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

281+
if func_args:
282+
# We need to tell pytest that the original function requires its fixtures,
283+
# otherwise indirect fixtures would not work.
284+
scenario_wrapper = pytest.mark.usefixtures(*func_args)(scenario_wrapper)
285+
284286
example_parametrizations = collect_example_parametrizations(templated_scenario)
285287
if example_parametrizations is not None:
286288
# Parametrize the scenario outlines
@@ -295,7 +297,7 @@ def scenario_wrapper(request: FixtureRequest, _pytest_bdd_example: dict[str, str
295297
config.hook.pytest_bdd_apply_tag(tag=tag, function=scenario_wrapper)
296298

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

301303
return decorator

0 commit comments

Comments
 (0)