()
| 437 | |
| 438 | |
| 439 | def test_unwrapped_match_check() -> None: |
| 440 | def my_check(e: object) -> bool: # pragma: no cover |
| 441 | return True |
| 442 | |
| 443 | msg = ( |
| 444 | "`allow_unwrapped=True` bypasses the `match` and `check` parameters" |
| 445 | " if the exception is unwrapped. If you intended to match/check the" |
| 446 | " exception you should use a `RaisesExc` object. If you want to match/check" |
| 447 | " the exceptiongroup when the exception *is* wrapped you need to" |
| 448 | " do e.g. `if isinstance(exc.value, ExceptionGroup):" |
| 449 | " assert RaisesGroup(...).matches(exc.value)` afterwards." |
| 450 | ) |
| 451 | with pytest.raises(ValueError, match=re.escape(msg)): |
| 452 | RaisesGroup(ValueError, allow_unwrapped=True, match="foo") # type: ignore[call-overload] |
| 453 | with pytest.raises(ValueError, match=re.escape(msg)): |
| 454 | RaisesGroup(ValueError, allow_unwrapped=True, check=my_check) # type: ignore[call-overload] |
| 455 | |
| 456 | # Users should instead use a RaisesExc |
| 457 | rg = RaisesGroup(RaisesExc(ValueError, match="^foo$"), allow_unwrapped=True) |
| 458 | with rg: |
| 459 | raise ValueError("foo") |
| 460 | with rg: |
| 461 | raise ExceptionGroup("", [ValueError("foo")]) |
| 462 | |
| 463 | # or if they wanted to match/check the group, do a conditional `.matches()` |
| 464 | with RaisesGroup(ValueError, allow_unwrapped=True) as exc: |
| 465 | raise ExceptionGroup("bar", [ValueError("foo")]) |
| 466 | if isinstance(exc.value, ExceptionGroup): # pragma: no branch |
| 467 | assert RaisesGroup(ValueError, match="bar").matches(exc.value) |
| 468 | |
| 469 | |
| 470 | def test_matches() -> None: |
nothing calls this directly
no test coverage detected