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

Function test_annotated_group

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

Source from the content-addressed store, hash-verified

1296
1297
1298def test_annotated_group() -> None:
1299 # repr depends on if exceptiongroup backport is being used or not
1300 t = repr(ExceptionGroup[ValueError])
1301 msg = "Only `ExceptionGroup[Exception]` or `BaseExceptionGroup[BaseException]` are accepted as generic types but got `{}`. As `raises` will catch all instances of the specified group regardless of the generic argument specific nested exceptions has to be checked with `RaisesGroup`."
1302
1303 fail_msg = wrap_escape(msg.format(t))
1304 with pytest.raises(ValueError, match=fail_msg):
1305 RaisesGroup(ExceptionGroup[ValueError])
1306 with pytest.raises(ValueError, match=fail_msg):
1307 RaisesExc(ExceptionGroup[ValueError])
1308 with pytest.raises(
1309 ValueError,
1310 match=wrap_escape(msg.format(repr(BaseExceptionGroup[KeyboardInterrupt]))),
1311 ):
1312 with RaisesExc(BaseExceptionGroup[KeyboardInterrupt]):
1313 raise BaseExceptionGroup("", [KeyboardInterrupt()])
1314
1315 with RaisesGroup(ExceptionGroup[Exception]):
1316 raise ExceptionGroup(
1317 "", [ExceptionGroup("", [ValueError(), ValueError(), ValueError()])]
1318 )
1319 with RaisesExc(BaseExceptionGroup[BaseException]):
1320 raise BaseExceptionGroup("", [KeyboardInterrupt()])
1321
1322 # assure AbstractRaises.is_baseexception is set properly
1323 assert (
1324 RaisesGroup(ExceptionGroup[Exception]).expected_type()
1325 == "ExceptionGroup(ExceptionGroup)"
1326 )
1327 assert (
1328 RaisesGroup(BaseExceptionGroup[BaseException]).expected_type()
1329 == "BaseExceptionGroup(BaseExceptionGroup)"
1330 )
1331
1332
1333def test_tuples() -> None:

Callers

nothing calls this directly

Calls 5

RaisesGroupClass · 0.90
RaisesExcClass · 0.90
expected_typeMethod · 0.80
wrap_escapeFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected