@@ -25,8 +25,26 @@ _P = ParamSpec("_P")
25
25
DIFF_OMITTED : str
26
26
27
27
class _BaseTestCaseContext :
28
+ test_case : TestCase
28
29
def __init__ (self , test_case : TestCase ) -> None : ...
29
30
31
+ class _AssertRaisesBaseContext (_BaseTestCaseContext ):
32
+ expected : type [BaseException ] | tuple [type [BaseException ], ...]
33
+ expected_regex : Pattern [str ] | None
34
+ obj_name : str | None
35
+ msg : str | None
36
+
37
+ def __init__ (
38
+ self ,
39
+ expected : type [BaseException ] | tuple [type [BaseException ], ...],
40
+ test_case : TestCase ,
41
+ expected_regex : str | Pattern [str ] | None = None ,
42
+ ) -> None : ...
43
+
44
+ # This returns Self if args is the empty list, and None otherwise.
45
+ # but it's not possible to construct an overload which expresses that
46
+ def handle (self , name : str , args : list [Any ], kwargs : dict [str , Any ]) -> Any : ...
47
+
30
48
if sys .version_info >= (3 , 9 ):
31
49
from unittest ._log import _AssertLogsContext , _LoggingWatcher
32
50
else :
41
59
42
60
class _AssertLogsContext (_BaseTestCaseContext , Generic [_L ]):
43
61
LOGGING_FORMAT : ClassVar [str ]
44
- test_case : TestCase
45
62
logger_name : str
46
63
level : int
47
64
msg : None
@@ -310,7 +327,7 @@ class FunctionTestCase(TestCase):
310
327
def __hash__ (self ) -> int : ...
311
328
def __eq__ (self , other : object ) -> bool : ...
312
329
313
- class _AssertRaisesContext (Generic [_E ]):
330
+ class _AssertRaisesContext (_AssertRaisesBaseContext , Generic [_E ]):
314
331
exception : _E
315
332
def __enter__ (self ) -> Self : ...
316
333
def __exit__ (
@@ -319,7 +336,7 @@ class _AssertRaisesContext(Generic[_E]):
319
336
if sys .version_info >= (3 , 9 ):
320
337
def __class_getitem__ (cls , item : Any ) -> GenericAlias : ...
321
338
322
- class _AssertWarnsContext :
339
+ class _AssertWarnsContext ( _AssertRaisesBaseContext ) :
323
340
warning : WarningMessage
324
341
filename : str
325
342
lineno : int
0 commit comments