From 5a2a58074a363a86f75d712c2a9ea026ac7f0bc3 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Tue, 18 Jul 2017 11:12:44 -0400 Subject: [PATCH] Move the step evaluation into a hook By moving it into a hook, it mirrors pytest's pytest_pyfunc_call, allowing a user to control how a step ends up being evaluated. --- pytest_bdd/hooks.py | 5 +++++ pytest_bdd/plugin.py | 6 ++++++ pytest_bdd/scenario.py | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pytest_bdd/hooks.py b/pytest_bdd/hooks.py index b3ec01e5..25f4fa42 100644 --- a/pytest_bdd/hooks.py +++ b/pytest_bdd/hooks.py @@ -19,6 +19,11 @@ def pytest_bdd_before_step_call(request, feature, scenario, step, step_func, ste """Called before step function is executed.""" +@pytest.hookspec(firstresult=True) +def pytest_bdd_call_step(request, feature, scenario, step, step_func, step_func_args): + """Call the underlying step.""" + + def pytest_bdd_after_step(request, feature, scenario, step, step_func, step_func_args): """Called after step function is successfully executed.""" diff --git a/pytest_bdd/plugin.py b/pytest_bdd/plugin.py index 1da65498..af2e8577 100644 --- a/pytest_bdd/plugin.py +++ b/pytest_bdd/plugin.py @@ -70,6 +70,12 @@ def pytest_bdd_before_step(request, feature, scenario, step, step_func): reporting.before_step(request, feature, scenario, step, step_func) +@pytest.mark.trylast +def pytest_bdd_call_step(request, feature, scenario, step, step_func, step_func_args): + step_func(**step_func_args) + return True + + @pytest.mark.tryfirst def pytest_bdd_after_step(request, feature, scenario, step, step_func, step_func_args): reporting.after_step(request, feature, scenario, step, step_func, step_func_args) diff --git a/pytest_bdd/scenario.py b/pytest_bdd/scenario.py index 07a52132..f015634c 100644 --- a/pytest_bdd/scenario.py +++ b/pytest_bdd/scenario.py @@ -134,7 +134,7 @@ def _execute_step_function(request, scenario, step, step_func): request.config.hook.pytest_bdd_before_step_call(**kw) # Execute the step. - step_func(**kwargs) + request.config.hook.pytest_bdd_call_step(**kw) request.config.hook.pytest_bdd_after_step(**kw) except Exception as exception: request.config.hook.pytest_bdd_step_error(exception=exception, **kw)