When rendered as JSON, the "Trace.stacks" is stripped, so "exceptions" is a list of lists and not a list of objects (with a single "stacks" attribute.
()
| 933 | sys.version_info < (3, 11), reason="Requires Python 3.11 or higher" |
| 934 | ) |
| 935 | def test_json_exception_groups() -> None: |
| 936 | """ |
| 937 | When rendered as JSON, the "Trace.stacks" is stripped, so "exceptions" is a |
| 938 | list of lists and not a list of objects (with a single "stacks" attribute. |
| 939 | """ |
| 940 | |
| 941 | lineno = get_next_lineno() |
| 942 | |
| 943 | async def t1() -> None: |
| 944 | 1 / 0 |
| 945 | |
| 946 | async def t2() -> None: |
| 947 | raise ValueError("Blam!") |
| 948 | |
| 949 | async def main(): |
| 950 | async with asyncio.TaskGroup() as tg: |
| 951 | tg.create_task(t1()) |
| 952 | tg.create_task(t2()) |
| 953 | |
| 954 | try: |
| 955 | asyncio.run(main()) |
| 956 | except Exception as e: |
| 957 | format_json = tracebacks.ExceptionDictTransformer(show_locals=False) |
| 958 | result = format_json((type(e), e, e.__traceback__)) |
| 959 | |
| 960 | assert "ExceptionGroup" == result[0]["exc_type"] |
| 961 | exceptions = result[0]["exceptions"] |
| 962 | assert [ |
| 963 | [ |
| 964 | { |
| 965 | "exc_type": "ZeroDivisionError", |
| 966 | "exc_value": "division by zero", |
| 967 | "exc_notes": [], |
| 968 | "syntax_error": None, |
| 969 | "is_cause": False, |
| 970 | "frames": [ |
| 971 | { |
| 972 | "filename": __file__, |
| 973 | "lineno": lineno + 2, |
| 974 | "name": "t1", |
| 975 | } |
| 976 | ], |
| 977 | "is_group": False, |
| 978 | "exceptions": [], |
| 979 | } |
| 980 | ], |
| 981 | [ |
| 982 | { |
| 983 | "exc_type": "ValueError", |
| 984 | "exc_value": "Blam!", |
| 985 | "exc_notes": [], |
| 986 | "syntax_error": None, |
| 987 | "is_cause": False, |
| 988 | "frames": [ |
| 989 | { |
| 990 | "filename": __file__, |
| 991 | "lineno": lineno + 5, |
| 992 | "name": "t2", |
nothing calls this directly
no test coverage detected
searching dependent graphs…