Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving Issue #11457 #11669

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -347,6 +347,7 @@ Sanket Duthade
Sankt Petersbug
Saravanan Padmanaban
Sean Malloy
Sean Pourgoutzidis
Segev Finer
Serhii Mozghovyi
Seth Junot
Expand Down
25 changes: 21 additions & 4 deletions src/_pytest/outcomes.py
Expand Up @@ -169,7 +169,12 @@


@_with_exception(Failed)
def fail(reason: str = "", pytrace: bool = True, msg: Optional[str] = None) -> NoReturn:
def fail(
reason: str = "",
pytrace: bool = True,
msg: Optional[str] = None,
suppress_context=False,
) -> NoReturn:
"""Explicitly fail an executing test with the given message.

:param reason:
Expand All @@ -181,10 +186,22 @@

:param msg:
Same as ``reason``, but deprecated. Will be removed in a future version, use ``reason`` instead.

:param suppressContext:
If true, prevents test from printing the context of internal errors.
"""
__tracebackhide__ = True
reason = _resolve_msg_to_reason("fail", reason, msg)
raise Failed(msg=reason, pytrace=pytrace)

if suppress_context:
try:
__tracebackhide__ = True
reason = _resolve_msg_to_reason("fail", reason, msg)
raise Failed(msg=reason, pytrace=pytrace)
except BaseException as e:
e.__cause__ = None
raise

Check warning on line 201 in src/_pytest/outcomes.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/outcomes.py#L195-L201

Added lines #L195 - L201 were not covered by tests
else:
reason = _resolve_msg_to_reason("fail", reason, msg)
raise Failed(msg=reason, pytrace=pytrace)


def _resolve_msg_to_reason(
Expand Down