Skip to content

Commit 1542a1c

Browse files
authored
OutcomeExceptions: remove '__module__ = "builtins"' hack (#19)
Ref: #6027
1 parent 08a7ae0 commit 1542a1c

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

doc/en/warnings.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ argument ``match`` to assert that the exception matches a text or regex::
276276
... warnings.warn("this is not here", UserWarning)
277277
Traceback (most recent call last):
278278
...
279-
Failed: DID NOT WARN. No warnings of type ...UserWarning... was emitted...
279+
_pytest.outcomes.Failed: DID NOT WARN. No warnings of type ...UserWarning... was emitted...
280280

281281
You can also call ``pytest.warns`` on a function or code string:
282282

src/_pytest/_code/code.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import _pytest
2828
from _pytest._io.saferepr import safeformat
2929
from _pytest._io.saferepr import saferepr
30+
from _pytest.outcomes import OutcomeException
3031

3132
if False: # TYPE_CHECKING
3233
from typing import Type
@@ -521,6 +522,10 @@ def exconly(self, tryshort: bool = False) -> str:
521522
removed from the beginning)
522523
"""
523524
lines = format_exception_only(self.type, self.value)
525+
if isinstance(self.value, OutcomeException):
526+
# Remove module prefix.
527+
assert lines[0].startswith(self.type.__module__), (lines[0], self.type)
528+
lines[0] = lines[0][len(self.type.__module__) + 1 :]
524529
text = "".join(lines)
525530
text = text.rstrip()
526531
if tryshort:

src/_pytest/outcomes.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ def __repr__(self) -> str:
4040

4141

4242
class Skipped(OutcomeException):
43-
# XXX hackish: on 3k we fake to live in the builtins
44-
# in order to have Skipped exception printing shorter/nicer
45-
__module__ = "builtins"
46-
4743
def __init__(
4844
self,
4945
msg: Optional[str] = None,
@@ -57,8 +53,6 @@ def __init__(
5753
class Failed(OutcomeException):
5854
""" raised from an explicit call to pytest.fail() """
5955

60-
__module__ = "builtins"
61-
6256

6357
class Exit(Exception):
6458
""" raised for immediate program exits (no tracebacks/summaries)"""

src/_pytest/recwarn.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ def warns( # noqa: F811
108108
... warnings.warn("this is not here", UserWarning)
109109
Traceback (most recent call last):
110110
...
111-
Failed: DID NOT WARN. No warnings of type ...UserWarning... was emitted...
112-
111+
_pytest.outcomes.Failed: DID NOT WARN. No warnings of type ...UserWarning... was emitted...
113112
"""
114113
__tracebackhide__ = True
115114
if not args:

0 commit comments

Comments
 (0)