Skip to content

[PR #14391/cd7592c4 backport][9.0.x] Use direct cause for raises match failures#14420

Merged
bluetech merged 1 commit into9.0.xfrom
patchback/backports/9.0.x/cd7592c41c40ebc9663c2984447d72e95c731bda/pr-14391
Apr 26, 2026
Merged

[PR #14391/cd7592c4 backport][9.0.x] Use direct cause for raises match failures#14420
bluetech merged 1 commit into9.0.xfrom
patchback/backports/9.0.x/cd7592c41c40ebc9663c2984447d72e95c731bda/pr-14391

Conversation

@patchback
Copy link
Copy Markdown

@patchback patchback Bot commented Apr 26, 2026

This is a backport of PR #14391 as merged into main (cd7592c).

Summary

  • raise the match-failure AssertionError with the original exception as its direct cause
  • add a regression test covering the direct-cause traceback wording
  • add the required changelog fragment and author entry

Why

When pytest.raises(..., match=...) fails because the regex does not match, the resulting traceback currently reports the original exception as implicit context. Raising the AssertionError with from exc_val preserves the original exception as the direct cause instead, which matches the issue expectation and produces clearer output.

Closes #14389.

Testing

  • env PYTHONPATH=/Users/garion/Work/pytest/src /Users/garion/Work/pytest/.venv/bin/python -m pytest /Users/garion/Work/pytest/testing/python/raises.py

@bluetech bluetech force-pushed the patchback/backports/9.0.x/cd7592c41c40ebc9663c2984447d72e95c731bda/pr-14391 branch from 815251c to 0931840 Compare April 26, 2026 08:09
@bluetech bluetech enabled auto-merge April 26, 2026 08:09
@bluetech bluetech merged commit e885db4 into 9.0.x Apr 26, 2026
33 checks passed
@bluetech bluetech deleted the patchback/backports/9.0.x/cd7592c41c40ebc9663c2984447d72e95c731bda/pr-14391 branch April 26, 2026 08:27
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.

2 participants