Skip to content

Commit e7c7f54

Browse files
committed
tighten the try-body so that we catch only in case of step failure
1 parent 7aca49b commit e7c7f54

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

pytest_bdd/scenario.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,34 @@ def _execute_step_function(
8080
}
8181

8282
request.config.hook.pytest_bdd_before_step(**kw)
83-
try: # TODO: Move this to the places where an exception can actually be raised
84-
# Get the step argument values.
85-
converters = context.converters
86-
kwargs = {}
8783

88-
for arg, value in context.parser.parse_arguments(step.name).items():
89-
if arg in converters:
90-
value = converters[arg](value)
91-
kwargs[arg] = value
84+
# Get the step argument values.
85+
converters = context.converters
86+
kwargs = {}
9287

93-
args = get_args(context.step_func)
94-
kwargs = {arg: kwargs[arg] if arg in kwargs else request.getfixturevalue(arg) for arg in args}
95-
kw["step_func_args"] = kwargs
88+
for arg, value in context.parser.parse_arguments(step.name).items():
89+
if arg in converters:
90+
value = converters[arg](value)
91+
kwargs[arg] = value
9692

97-
request.config.hook.pytest_bdd_before_step_call(**kw)
93+
args = get_args(context.step_func)
94+
kwargs = {arg: kwargs[arg] if arg in kwargs else request.getfixturevalue(arg) for arg in args}
95+
kw["step_func_args"] = kwargs
9896

97+
request.config.hook.pytest_bdd_before_step_call(**kw)
98+
99+
try:
99100
# Execute the step as if it was a pytest fixture, so that we can allow "yield" statements in it
100101
return_value = call_fixture_func(fixturefunc=context.step_func, request=request, kwargs=kwargs)
101-
if context.target_fixture is not None:
102-
inject_fixture(request, context.target_fixture, return_value)
103-
104-
request.config.hook.pytest_bdd_after_step(**kw)
105102
except Exception as exception:
106103
request.config.hook.pytest_bdd_step_error(exception=exception, **kw)
107104
raise
108105

106+
if context.target_fixture is not None:
107+
inject_fixture(request, context.target_fixture, return_value)
108+
109+
request.config.hook.pytest_bdd_after_step(**kw)
110+
109111

110112
def _execute_scenario(feature: Feature, scenario: Scenario, request: FixtureRequest) -> None:
111113
"""Execute the scenario.

0 commit comments

Comments
 (0)