3
3
as well as functions creating them
4
4
"""
5
5
import sys
6
+ from typing import Any
7
+ from typing import Optional
6
8
7
9
from packaging .version import Version
8
10
11
+ if False : # TYPE_CHECKING
12
+ from typing import NoReturn
13
+
9
14
10
15
class OutcomeException (BaseException ):
11
16
""" OutcomeException and its subclass instances indicate and
12
17
contain info about test and collection outcomes.
13
18
"""
14
19
15
- def __init__ (self , msg = None , pytrace = True ):
20
+ def __init__ (self , msg : Optional [ str ] = None , pytrace : bool = True ) -> None :
16
21
BaseException .__init__ (self , msg )
17
22
self .msg = msg
18
23
self .pytrace = pytrace
19
24
20
- def __repr__ (self ):
25
+ def __repr__ (self ) -> str :
21
26
if self .msg :
22
27
val = self .msg
23
28
if isinstance (val , bytes ):
@@ -36,7 +41,12 @@ class Skipped(OutcomeException):
36
41
# in order to have Skipped exception printing shorter/nicer
37
42
__module__ = "builtins"
38
43
39
- def __init__ (self , msg = None , pytrace = True , allow_module_level = False ):
44
+ def __init__ (
45
+ self ,
46
+ msg : Optional [str ] = None ,
47
+ pytrace : bool = True ,
48
+ allow_module_level : bool = False ,
49
+ ) -> None :
40
50
OutcomeException .__init__ (self , msg = msg , pytrace = pytrace )
41
51
self .allow_module_level = allow_module_level
42
52
@@ -50,7 +60,9 @@ class Failed(OutcomeException):
50
60
class Exit (Exception ):
51
61
""" raised for immediate program exits (no tracebacks/summaries)"""
52
62
53
- def __init__ (self , msg = "unknown reason" , returncode = None ):
63
+ def __init__ (
64
+ self , msg : str = "unknown reason" , returncode : Optional [int ] = None
65
+ ) -> None :
54
66
self .msg = msg
55
67
self .returncode = returncode
56
68
super ().__init__ (msg )
@@ -59,7 +71,7 @@ def __init__(self, msg="unknown reason", returncode=None):
59
71
# exposed helper methods
60
72
61
73
62
- def exit (msg , returncode = None ):
74
+ def exit (msg : str , returncode : Optional [ int ] = None ) -> "NoReturn" :
63
75
"""
64
76
Exit testing process.
65
77
@@ -74,7 +86,7 @@ def exit(msg, returncode=None):
74
86
exit .Exception = Exit # type: ignore
75
87
76
88
77
- def skip (msg = "" , * , allow_module_level = False ):
89
+ def skip (msg : str = "" , * , allow_module_level : bool = False ) -> "NoReturn" :
78
90
"""
79
91
Skip an executing test with the given message.
80
92
@@ -101,7 +113,7 @@ def skip(msg="", *, allow_module_level=False):
101
113
skip .Exception = Skipped # type: ignore
102
114
103
115
104
- def fail (msg = "" , pytrace = True ):
116
+ def fail (msg : str = "" , pytrace : bool = True ) -> "NoReturn" :
105
117
"""
106
118
Explicitly fail an executing test with the given message.
107
119
@@ -121,7 +133,7 @@ class XFailed(Failed):
121
133
""" raised from an explicit call to pytest.xfail() """
122
134
123
135
124
- def xfail (reason = "" ):
136
+ def xfail (reason : str = "" ) -> "NoReturn" :
125
137
"""
126
138
Imperatively xfail an executing test or setup functions with the given reason.
127
139
@@ -139,7 +151,9 @@ def xfail(reason=""):
139
151
xfail .Exception = XFailed # type: ignore
140
152
141
153
142
- def importorskip (modname , minversion = None , reason = None ):
154
+ def importorskip (
155
+ modname : str , minversion : Optional [str ] = None , reason : Optional [str ] = None
156
+ ) -> Any :
143
157
"""Imports and returns the requested module ``modname``, or skip the current test
144
158
if the module cannot be imported.
145
159
0 commit comments