From 680478029488120e9ecce463242ed804d65e3faf Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 8 Jun 2026 10:14:22 +0000 Subject: [PATCH] Fix pytest.fail() not captured in cucumber JSON step output pytest.fail() raises _pytest.outcomes.Failed which inherits from BaseException, not Exception. The except Exception handler in _execute_step_function was bypassing the pytest_bdd_step_error hook, leaving the step's failed flag as False and causing all steps to appear as "passed" in the JSON output even when the test failed. https://claude.ai/code/session_012zuaUetLWHn9VgJZ99moaX --- src/pytest_bdd/scenario.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_bdd/scenario.py b/src/pytest_bdd/scenario.py index 531190617..4398722e2 100644 --- a/src/pytest_bdd/scenario.py +++ b/src/pytest_bdd/scenario.py @@ -247,7 +247,7 @@ def _execute_step_function( # so that we can allow "yield" statements in it return_value = call_fixture_func(fixturefunc=context.step_func, request=request, kwargs=kwargs) - except Exception as exception: + except BaseException as exception: request.config.hook.pytest_bdd_step_error(exception=exception, **kw) raise