@@ -472,35 +472,65 @@ def test_doesnt_contain_exception_match(self) -> None:
472
472
raise exc_group
473
473
assert not exc_info .group_contains (RuntimeError , match = r"^exception message$" )
474
474
475
- def test_contains_exception_type_recursive (self ) -> None :
475
+ def test_contains_exception_type_unlimited_depth (self ) -> None :
476
476
exc_group = ExceptionGroup ("" , [ExceptionGroup ("" , [RuntimeError ()])])
477
477
with pytest .raises (ExceptionGroup ) as exc_info :
478
478
raise exc_group
479
- assert exc_info .group_contains (RuntimeError , recursive = True )
479
+ assert exc_info .group_contains (RuntimeError )
480
480
481
- def test_doesnt_contain_exception_type_nonrecursive (self ) -> None :
481
+ def test_contains_exception_type_at_depth_1 (self ) -> None :
482
+ exc_group = ExceptionGroup ("" , [RuntimeError ()])
483
+ with pytest .raises (ExceptionGroup ) as exc_info :
484
+ raise exc_group
485
+ assert exc_info .group_contains (RuntimeError , depth = 1 )
486
+
487
+ def test_doesnt_contain_exception_type_past_depth (self ) -> None :
482
488
exc_group = ExceptionGroup ("" , [ExceptionGroup ("" , [RuntimeError ()])])
483
489
with pytest .raises (ExceptionGroup ) as exc_info :
484
490
raise exc_group
485
- assert not exc_info .group_contains (RuntimeError )
491
+ assert not exc_info .group_contains (RuntimeError , depth = 1 )
486
492
487
- def test_contains_exception_match_recursive (self ) -> None :
493
+ def test_contains_exception_type_specific_depth (self ) -> None :
494
+ exc_group = ExceptionGroup ("" , [ExceptionGroup ("" , [RuntimeError ()])])
495
+ with pytest .raises (ExceptionGroup ) as exc_info :
496
+ raise exc_group
497
+ assert exc_info .group_contains (RuntimeError , depth = 2 )
498
+
499
+ def test_contains_exception_match_unlimited_depth (self ) -> None :
488
500
exc_group = ExceptionGroup (
489
501
"" , [ExceptionGroup ("" , [RuntimeError ("exception message" )])]
490
502
)
503
+ with pytest .raises (ExceptionGroup ) as exc_info :
504
+ raise exc_group
505
+ assert exc_info .group_contains (RuntimeError , match = r"^exception message$" )
506
+
507
+ def test_contains_exception_match_at_depth_1 (self ) -> None :
508
+ exc_group = ExceptionGroup ("" , [RuntimeError ("exception message" )])
491
509
with pytest .raises (ExceptionGroup ) as exc_info :
492
510
raise exc_group
493
511
assert exc_info .group_contains (
494
- RuntimeError , match = r"^exception message$" , recursive = True
512
+ RuntimeError , match = r"^exception message$" , depth = 1
495
513
)
496
514
497
- def test_doesnt_contain_exception_match_nonrecursive (self ) -> None :
515
+ def test_doesnt_contain_exception_match_past_depth (self ) -> None :
498
516
exc_group = ExceptionGroup (
499
- "" , [ExceptionGroup ("" , [RuntimeError ("message that will not match " )])]
517
+ "" , [ExceptionGroup ("" , [RuntimeError ("exception message " )])]
500
518
)
501
519
with pytest .raises (ExceptionGroup ) as exc_info :
502
520
raise exc_group
503
- assert not exc_info .group_contains (RuntimeError , match = r"^exception message$" )
521
+ assert not exc_info .group_contains (
522
+ RuntimeError , match = r"^exception message$" , depth = 1
523
+ )
524
+
525
+ def test_contains_exception_match_specific_depth (self ) -> None :
526
+ exc_group = ExceptionGroup (
527
+ "" , [ExceptionGroup ("" , [RuntimeError ("exception message" )])]
528
+ )
529
+ with pytest .raises (ExceptionGroup ) as exc_info :
530
+ raise exc_group
531
+ assert exc_info .group_contains (
532
+ RuntimeError , match = r"^exception message$" , depth = 2
533
+ )
504
534
505
535
506
536
class TestFormattedExcinfo :
0 commit comments