summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2022-11-18 15:44:43 (GMT)
committerGitHub <noreply@github.com>2022-11-18 15:44:43 (GMT)
commitc8c6113398ee9a7867fe9b08bc539cceb61e2aaa (patch)
tree61ce8fc106b5578aeeeb524703bd195eabffab0a /Lib/test
parenta220c6d1ee3053895f502b43b47dc3a9c55fa6a3 (diff)
downloadcpython-c8c6113398ee9a7867fe9b08bc539cceb61e2aaa.zip
cpython-c8c6113398ee9a7867fe9b08bc539cceb61e2aaa.tar.gz
cpython-c8c6113398ee9a7867fe9b08bc539cceb61e2aaa.tar.bz2
gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException (GH-99572)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_exception_group.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/Lib/test/test_exception_group.py b/Lib/test/test_exception_group.py
index aa28e16..b11524e 100644
--- a/Lib/test/test_exception_group.py
+++ b/Lib/test/test_exception_group.py
@@ -78,16 +78,30 @@ class InstanceCreation(unittest.TestCase):
beg = BaseExceptionGroup("beg", [ValueError(1), KeyboardInterrupt(2)])
self.assertIs(type(beg), BaseExceptionGroup)
- def test_EG_subclass_wraps_anything(self):
+ def test_EG_subclass_wraps_non_base_exceptions(self):
class MyEG(ExceptionGroup):
pass
self.assertIs(
type(MyEG("eg", [ValueError(12), TypeError(42)])),
MyEG)
- self.assertIs(
- type(MyEG("eg", [ValueError(12), KeyboardInterrupt(42)])),
- MyEG)
+
+ def test_EG_subclass_does_not_wrap_base_exceptions(self):
+ class MyEG(ExceptionGroup):
+ pass
+
+ msg = "Cannot nest BaseExceptions in 'MyEG'"
+ with self.assertRaisesRegex(TypeError, msg):
+ MyEG("eg", [ValueError(12), KeyboardInterrupt(42)])
+
+ def test_BEG_and_E_subclass_does_not_wrap_base_exceptions(self):
+ class MyEG(BaseExceptionGroup, ValueError):
+ pass
+
+ msg = "Cannot nest BaseExceptions in 'MyEG'"
+ with self.assertRaisesRegex(TypeError, msg):
+ MyEG("eg", [ValueError(12), KeyboardInterrupt(42)])
+
def test_BEG_subclass_wraps_anything(self):
class MyBEG(BaseExceptionGroup):