gh-106300: Improve assertRaises(Exception) usages in tests (GH-106302)

This commit is contained in:
Nikita Sobolev 2023-07-07 23:42:40 +03:00 committed by GitHub
parent 80b9b3a517
commit 6e6a4cd523
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 12 deletions

View file

@ -448,15 +448,16 @@ def test_factory(abc_ABCMeta, abc_get_cache_token):
# Also check that issubclass() propagates exceptions raised by
# __subclasses__.
class CustomError(Exception): ...
exc_msg = "exception from __subclasses__"
def raise_exc():
raise Exception(exc_msg)
raise CustomError(exc_msg)
class S(metaclass=abc_ABCMeta):
__subclasses__ = raise_exc
with self.assertRaisesRegex(Exception, exc_msg):
with self.assertRaisesRegex(CustomError, exc_msg):
issubclass(int, S)
def test_subclasshook(self):