@@ -25,8 +25,26 @@ _P = ParamSpec("_P")
2525DIFF_OMITTED : str
2626
2727class _BaseTestCaseContext :
28+ test_case : TestCase
2829 def __init__ (self , test_case : TestCase ) -> None : ...
2930
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+
3048if sys .version_info >= (3 , 9 ):
3149 from unittest ._log import _AssertLogsContext , _LoggingWatcher
3250else :
4159
4260 class _AssertLogsContext (_BaseTestCaseContext , Generic [_L ]):
4361 LOGGING_FORMAT : ClassVar [str ]
44- test_case : TestCase
4562 logger_name : str
4663 level : int
4764 msg : None
@@ -310,7 +327,7 @@ class FunctionTestCase(TestCase):
310327 def __hash__ (self ) -> int : ...
311328 def __eq__ (self , other : object ) -> bool : ...
312329
313- class _AssertRaisesContext (Generic [_E ]):
330+ class _AssertRaisesContext (_AssertRaisesBaseContext , Generic [_E ]):
314331 exception : _E
315332 def __enter__ (self ) -> Self : ...
316333 def __exit__ (
@@ -319,7 +336,7 @@ class _AssertRaisesContext(Generic[_E]):
319336 if sys .version_info >= (3 , 9 ):
320337 def __class_getitem__ (cls , item : Any ) -> GenericAlias : ...
321338
322- class _AssertWarnsContext :
339+ class _AssertWarnsContext ( _AssertRaisesBaseContext ) :
323340 warning : WarningMessage
324341 filename : str
325342 lineno : int
0 commit comments