add test
This commit is contained in:
parent
ed054c6379
commit
2a64ad4fd5
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue