@@ -162,32 +162,44 @@ class Descriptor:
162162 def __set_name__ (self , owner , name ):
163163 1 / ZERO
164164
165- with self .assertRaises (RuntimeError ) as cm :
165+ with self .assertRaises (( RuntimeError , ZeroDivisionError ) ) as cm :
166166 class NotGoingToWork :
167167 attr = Descriptor ()
168168
169- exc = cm .exception
170- self .assertRegex (str (exc ), r'\bNotGoingToWork\b' )
171- self .assertRegex (str (exc ), r'\battr\b' )
172- self .assertRegex (str (exc ), r'\bDescriptor\b' )
173- if HAS_NATIVE_SUPPORT :
174- self .assertIsInstance (exc .__cause__ , ZeroDivisionError )
169+ if sys .version_info >= (3 , 12 ):
170+ notes = cm .exception .__notes__
171+ self .assertRegex (str (notes ), r'\bNotGoingToWork\b' )
172+ self .assertRegex (str (notes ), r'\battr\b' )
173+ self .assertRegex (str (notes ), r'\bDescriptor\b' )
174+ else :
175+ exc = cm .exception
176+ self .assertRegex (str (exc ), r'\bNotGoingToWork\b' )
177+ self .assertRegex (str (exc ), r'\battr\b' )
178+ self .assertRegex (str (exc ), r'\bDescriptor\b' )
179+ if HAS_NATIVE_SUPPORT :
180+ self .assertIsInstance (exc .__cause__ , ZeroDivisionError )
175181
176182 def test_set_name_wrong (self ):
177183 class Descriptor :
178184 def __set_name__ (self ):
179185 pass
180186
181- with self .assertRaises (RuntimeError ) as cm :
187+ with self .assertRaises (( RuntimeError , TypeError ) ) as cm :
182188 class NotGoingToWork :
183189 attr = Descriptor ()
184190
185- exc = cm .exception
186- self .assertRegex (str (exc ), r'\bNotGoingToWork\b' )
187- self .assertRegex (str (exc ), r'\battr\b' )
188- self .assertRegex (str (exc ), r'\bDescriptor\b' )
189- if HAS_NATIVE_SUPPORT :
190- self .assertIsInstance (exc .__cause__ , TypeError )
191+ if sys .version_info >= (3 , 12 ):
192+ notes = cm .exception .__notes__
193+ self .assertRegex (str (notes ), r'\bNotGoingToWork\b' )
194+ self .assertRegex (str (notes ), r'\battr\b' )
195+ self .assertRegex (str (notes ), r'\bDescriptor\b' )
196+ else :
197+ exc = cm .exception
198+ self .assertRegex (str (exc ), r'\bNotGoingToWork\b' )
199+ self .assertRegex (str (exc ), r'\battr\b' )
200+ self .assertRegex (str (exc ), r'\bDescriptor\b' )
201+ if HAS_NATIVE_SUPPORT :
202+ self .assertIsInstance (exc .__cause__ , TypeError )
191203
192204 def test_set_name_lookup (self ):
193205 resolved = []
0 commit comments