Exception groups are detected and a list of Trace instances is added to the exception group's Trace.
()
| 572 | sys.version_info < (3, 11), reason="Requires Python 3.11 or higher" |
| 573 | ) |
| 574 | def test_exception_groups() -> None: |
| 575 | """ |
| 576 | Exception groups are detected and a list of Trace instances is added to |
| 577 | the exception group's Trace. |
| 578 | """ |
| 579 | lineno = get_next_lineno() |
| 580 | |
| 581 | async def t1() -> None: |
| 582 | 1 / 0 |
| 583 | |
| 584 | async def t2() -> None: |
| 585 | raise ValueError("Blam!") |
| 586 | |
| 587 | async def main(): |
| 588 | async with asyncio.TaskGroup() as tg: |
| 589 | tg.create_task(t1()) |
| 590 | tg.create_task(t2()) |
| 591 | |
| 592 | try: |
| 593 | asyncio.run(main()) |
| 594 | except Exception as e: |
| 595 | trace = tracebacks.extract(type(e), e, e.__traceback__) |
| 596 | |
| 597 | assert "ExceptionGroup" == trace.stacks[0].exc_type |
| 598 | assert ( |
| 599 | "unhandled errors in a TaskGroup (2 sub-exceptions)" |
| 600 | == trace.stacks[0].exc_value |
| 601 | ) |
| 602 | exceptions = trace.stacks[0].exceptions |
| 603 | assert [ |
| 604 | tracebacks.Trace( |
| 605 | stacks=[ |
| 606 | tracebacks.Stack( |
| 607 | exc_type="ZeroDivisionError", |
| 608 | exc_value="division by zero", |
| 609 | exc_notes=[], |
| 610 | syntax_error=None, |
| 611 | is_cause=False, |
| 612 | frames=[ |
| 613 | tracebacks.Frame( |
| 614 | filename=__file__, |
| 615 | lineno=lineno + 2, |
| 616 | name="t1", |
| 617 | locals=None, |
| 618 | ) |
| 619 | ], |
| 620 | is_group=False, |
| 621 | exceptions=[], |
| 622 | ) |
| 623 | ] |
| 624 | ), |
| 625 | tracebacks.Trace( |
| 626 | stacks=[ |
| 627 | tracebacks.Stack( |
| 628 | exc_type="ValueError", |
| 629 | exc_value="Blam!", |
| 630 | exc_notes=[], |
| 631 | syntax_error=None, |
nothing calls this directly
no test coverage detected
searching dependent graphs…