Skip to content

Fix pytest.fail() not captured in cucumber JSON step output#811

Open
jackhenderson101 wants to merge 2 commits into
pytest-dev:masterfrom
jackhenderson101:fix/pytest-fail-cucumber-json
Open

Fix pytest.fail() not captured in cucumber JSON step output#811
jackhenderson101 wants to merge 2 commits into
pytest-dev:masterfrom
jackhenderson101:fix/pytest-fail-cucumber-json

Conversation

@jackhenderson101

Copy link
Copy Markdown

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.

claude and others added 2 commits June 8, 2026 10:14
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
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.10%. Comparing base (9454b38) to head (a77484e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #811   +/-   ##
=======================================
  Coverage   96.10%   96.10%           
=======================================
  Files          55       55           
  Lines        2390     2390           
  Branches      136      136           
=======================================
  Hits         2297     2297           
  Misses         56       56           
  Partials       37       37           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hiSandog

hiSandog commented Jul 3, 2026

Copy link
Copy Markdown

Capturing pytest.fail() in cucumber JSON is the right direction, but the edge case is hook ordering around step teardown. It would be good to include a scenario where pytest.fail() happens inside the step body and another where failure is raised from a fixture/teardown path, then assert the JSON has the failed status and useful message in both cases. That keeps the report format reliable for CI consumers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants