@@ -5,6 +5,15 @@ def raise_error(err):
55 raise err
66
77
8+ def raise_error_from_another (out_err , another_err ):
9+ # use try..except approache so out_error have meaningful
10+ # __context__, __cause__ attribute.
11+ try :
12+ raise another_err
13+ except Exception as e :
14+ raise out_err from e
15+
16+
817def test_split_for_none_exception ():
918 matched , unmatched = split (RuntimeError , None )
1019 assert matched is None
@@ -79,7 +88,7 @@ def test_split_with_single_exception():
7988 assert unmatched is err
8089
8190
82- def test_split_with_same_traceback ():
91+ def test_split_and_check_attributes_same ():
8392 try :
8493 raise_error (RuntimeError ("RuntimeError" ))
8594 except Exception as e :
@@ -93,11 +102,16 @@ def test_split_with_same_traceback():
93102 group = ExceptionGroup (
94103 "ErrorGroup" , [run_error , val_error ], ["RuntimeError" , "ValueError" ]
95104 )
105+ # go and check __traceback__, __cause__ attributes
96106 try :
97- raise_error (group )
107+ raise_error_from_another (group , RuntimeError ( "Cause" ) )
98108 except BaseException as e :
99109 new_group = e
100110
101111 matched , unmatched = split (RuntimeError , group )
102112 assert matched .__traceback__ is new_group .__traceback__
113+ assert matched .__cause__ is new_group .__cause__
114+ assert matched .__context__ is new_group .__context__
103115 assert unmatched .__traceback__ is new_group .__traceback__
116+ assert unmatched .__cause__ is new_group .__cause__
117+ assert unmatched .__context__ is new_group .__context__
0 commit comments