Mark pytest outcome failures in cucumber JSON#815
Open
lin-hongkuan wants to merge 1 commit into
Open
Conversation
e64249a to
49c8eaf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #770.
Summary
When a step raises a pytest outcome exception, such as
pytest.fail()or the failure emitted bypytest-timeout, pytest-bdd currently does not callpytest_bdd_step_error. Those exceptions derive from pytest'sOutcomeException, which is aBaseException, so the existingexcept Exceptionblock does not catch them.That leaves the current
StepReportwith its defaultfailed=False, and cucumber JSON serializes the timed-out/failed step aspassed.This change catches pytest's
TEST_OUTCOMEtuple for step execution, preserving the existingExceptionhandling while also reporting pytest outcome failures through the step error hook. It does not catch unrelatedBaseExceptionsubclasses such asKeyboardInterruptorSystemExit.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 configuredpython_version = 3.9git diff --check origin/master...HEADI 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-bddconsole script, and the existing parser/output compatibility tests.