Skip to content

Mark pytest outcome failures in cucumber JSON#815

Open
lin-hongkuan wants to merge 1 commit into
pytest-dev:masterfrom
lin-hongkuan:codex/cucumber-json-outcome-failures
Open

Mark pytest outcome failures in cucumber JSON#815
lin-hongkuan wants to merge 1 commit into
pytest-dev:masterfrom
lin-hongkuan:codex/cucumber-json-outcome-failures

Conversation

@lin-hongkuan

@lin-hongkuan lin-hongkuan commented Jun 25, 2026

Copy link
Copy Markdown

Fixes #770.

Summary

When a step raises a pytest outcome exception, such as pytest.fail() or the failure emitted by pytest-timeout, pytest-bdd currently does not call pytest_bdd_step_error. Those exceptions derive from pytest's OutcomeException, which is a BaseException, so the existing except Exception block does not catch them.

That leaves the current StepReport with its default failed=False, and cucumber JSON serializes the timed-out/failed step as passed.

This change catches pytest's TEST_OUTCOME tuple for step execution, preserving the existing Exception handling while also reporting pytest outcome failures through the step error hook. It does not catch unrelated BaseException subclasses such as KeyboardInterrupt or SystemExit.

Tests

  • .\.venv\Scripts\python.exe -m pytest tests/feature/test_cucumber_json.py::test_pytest_outcome_exception_marks_step_failed -q
  • .\.venv\Scripts\python.exe -m pytest tests/feature/test_cucumber_json.py -q
  • .\.venv\Scripts\python.exe -m pytest tests/feature/test_cucumber_json.py tests/feature/test_report.py tests/feature/test_steps.py::test_step_hooks tests/feature/test_steps.py::test_step_trace -q -> 5 passed, 1 skipped
  • .\.venv\Scripts\ruff.exe check .
  • .\.venv\Scripts\ruff.exe format --check .
  • .\.venv\Scripts\mypy.exe src/pytest_bdd/scenario.py src/pytest_bdd/reporting.py src/pytest_bdd/plugin.py src/pytest_bdd/hooks.py -> no type issues; current mypy reports that this version no longer supports the repository's configured python_version = 3.9
  • git diff --check origin/master...HEAD

I also ran the full suite locally on Windows/Python 3.14. It currently has 9 failures unrelated to this change, mostly Windows path separator assertions, subprocess lookup of the pytest-bdd console script, and the existing parser/output compatibility tests.

@lin-hongkuan lin-hongkuan force-pushed the codex/cucumber-json-outcome-failures branch from e64249a to 49c8eaf Compare June 25, 2026 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cucumberjson compatibility with pytest-timeout

1 participant