MCPcopy
hub / github.com/pytest-dev/pytest / test_check

Function test_check

testing/python/raises_group.py:408–436  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

406
407
408def test_check() -> None:
409 exc = ExceptionGroup("", (ValueError(),))
410
411 def is_exc(e: ExceptionGroup[ValueError]) -> bool:
412 return e is exc
413
414 is_exc_repr = repr_callable(is_exc)
415 with RaisesGroup(ValueError, check=is_exc):
416 raise exc
417
418 with (
419 fails_raises_group(
420 f"check {is_exc_repr} did not return True on the ExceptionGroup"
421 ),
422 RaisesGroup(ValueError, check=is_exc),
423 ):
424 raise ExceptionGroup("", (ValueError(),))
425
426 def is_value_error(e: BaseException) -> bool:
427 return isinstance(e, ValueError)
428
429 # helpful suggestion if the user thinks the check is for the sub-exception
430 with (
431 fails_raises_group(
432 f"check {is_value_error} did not return True on the ExceptionGroup, but did return True for the expected ValueError. You might want RaisesGroup(RaisesExc(ValueError, check=<...>))"
433 ),
434 RaisesGroup(ValueError, check=is_value_error),
435 ):
436 raise ExceptionGroup("", (ValueError(),))
437
438
439def test_unwrapped_match_check() -> None:

Callers

nothing calls this directly

Calls 3

repr_callableFunction · 0.90
RaisesGroupClass · 0.90
fails_raises_groupFunction · 0.85

Tested by

no test coverage detected