diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index af72857f3..c79030cd5 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -1470,3 +1470,35 @@ def test_no_recursion_index_on_recursion_error(): with pytest.raises(RuntimeError) as excinfo: RecursionDepthError().trigger assert "maximum recursion" in str(excinfo.getrepr()) + + +@pytest.mark.skipif(sys.version_info < (3, 11), reason="requires python3.11 or higher") +def test_exceptiongroup(pytester: Pytester) -> None: + pytester.makepyfile( + """ + def f(): raise ValueError("From f()") + def g(): raise RuntimeError("From g()") + + def main(): + excs = [] + for callback in [f, g]: + try: + callback() + except Exception as err: + excs.append(err) + if excs: + raise ExceptionGroup("Oops", excs) + + def test(): + main() + """ + ) + result = pytester.runpytest() + assert result.ret != 0 + + match = [ + r" | ExceptionGroup: Oops (2 sub-exceptions)", + r" | ValueError: From f()", + r" | RuntimeError: From g()", + ] + result.stdout.re_match_lines(match)