File tree 4 files changed +7
-9
lines changed 4 files changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -276,7 +276,7 @@ argument ``match`` to assert that the exception matches a text or regex::
276
276
... warnings.warn("this is not here", UserWarning)
277
277
Traceback (most recent call last):
278
278
...
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...
280
280
281
281
You can also call ``pytest.warns `` on a function or code string:
282
282
Original file line number Diff line number Diff line change 27
27
import _pytest
28
28
from _pytest ._io .saferepr import safeformat
29
29
from _pytest ._io .saferepr import saferepr
30
+ from _pytest .outcomes import OutcomeException
30
31
31
32
if False : # TYPE_CHECKING
32
33
from typing import Type
@@ -521,6 +522,10 @@ def exconly(self, tryshort: bool = False) -> str:
521
522
removed from the beginning)
522
523
"""
523
524
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 :]
524
529
text = "" .join (lines )
525
530
text = text .rstrip ()
526
531
if tryshort :
Original file line number Diff line number Diff line change @@ -40,10 +40,6 @@ def __repr__(self) -> str:
40
40
41
41
42
42
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
-
47
43
def __init__ (
48
44
self ,
49
45
msg : Optional [str ] = None ,
@@ -57,8 +53,6 @@ def __init__(
57
53
class Failed (OutcomeException ):
58
54
""" raised from an explicit call to pytest.fail() """
59
55
60
- __module__ = "builtins"
61
-
62
56
63
57
class Exit (Exception ):
64
58
""" raised for immediate program exits (no tracebacks/summaries)"""
Original file line number Diff line number Diff line change @@ -108,8 +108,7 @@ def warns( # noqa: F811
108
108
... warnings.warn("this is not here", UserWarning)
109
109
Traceback (most recent call last):
110
110
...
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...
113
112
"""
114
113
__tracebackhide__ = True
115
114
if not args :
You can’t perform that action at this time.
0 commit comments