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

Function test_match

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

Source from the content-addressed store, hash-verified

357
358
359def test_match() -> None:
360 # supports match string
361 with RaisesGroup(ValueError, match="bar"):
362 raise ExceptionGroup("bar", (ValueError(),))
363
364 # now also works with ^$
365 with RaisesGroup(ValueError, match="^bar$"):
366 raise ExceptionGroup("bar", (ValueError(),))
367
368 # it also includes notes
369 with RaisesGroup(ValueError, match="my note"):
370 e = ExceptionGroup("bar", (ValueError(),))
371 e.add_note("my note")
372 raise e
373
374 # and technically you can match it all with ^$
375 # but you're probably better off using a RaisesExc at that point
376 with RaisesGroup(ValueError, match="^bar\nmy note$"):
377 e = ExceptionGroup("bar", (ValueError(),))
378 e.add_note("my note")
379 raise e
380
381 with (
382 fails_raises_group(
383 "Regex pattern did not match the `ExceptionGroup()`.\n"
384 " Expected regex: 'foo'\n"
385 " Actual message: 'bar'"
386 ),
387 RaisesGroup(ValueError, match="foo"),
388 ):
389 raise ExceptionGroup("bar", (ValueError(),))
390
391 # Suggest a fix for easy pitfall of adding match to the RaisesGroup instead of
392 # using a RaisesExc.
393 # This requires a single expected & raised exception, the expected is a type,
394 # and `isinstance(raised, expected_type)`.
395 with (
396 fails_raises_group(
397 "Regex pattern did not match the `ExceptionGroup()`.\n"
398 " Expected regex: 'foo'\n"
399 " Actual message: 'bar'\n"
400 " but matched the expected `ValueError`.\n"
401 " You might want `RaisesGroup(RaisesExc(ValueError, match='foo'))`"
402 ),
403 RaisesGroup(ValueError, match="foo"),
404 ):
405 raise ExceptionGroup("bar", [ValueError("foo")])
406
407
408def test_check() -> None:

Callers

nothing calls this directly

Calls 2

RaisesGroupClass · 0.90
fails_raises_groupFunction · 0.85

Tested by

no test coverage detected