From d20ffc64b14ef89e813bd30628684b4c9695155b Mon Sep 17 00:00:00 2001 From: Alexander683 <187546753+Alexander683@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:09:31 +0100 Subject: [PATCH] docs: clarify why OutcomeException inherits from BaseException Explain in OutcomeException's docstring that it inherits from BaseException rather than Exception so broad except Exception handlers do not accidentally swallow pytest outcomes without re-raising them. Closes #12235 Assisted-by: Gemini (Google Antigravity) --- src/_pytest/outcomes.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index 257b95cf585..3ee643b187e 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -12,7 +12,13 @@ class OutcomeException(BaseException): """OutcomeException and its subclass instances indicate and contain info - about test and collection outcomes.""" + about test and collection outcomes. + + Inherits from :class:`BaseException` rather than :class:`Exception` so that + broad ``except Exception:`` handlers in user code or tests do not + accidentally swallow pytest outcomes (such as :func:`pytest.skip`, + :func:`pytest.fail`, or :func:`pytest.xfail`) without re-raising them. + """ def __init__(self, msg: str | None = None, pytrace: bool = True) -> None: if msg is not None and not isinstance(msg, str):