MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_match_raises_error

Function test_match_raises_error

testing/code/test_excinfo.py:413–434  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

411
412
413def test_match_raises_error(pytester: Pytester) -> None:
414 pytester.makepyfile(
415 """
416 import pytest
417 def test_division_zero():
418 with pytest.raises(ZeroDivisionError) as excinfo:
419 0 / 0
420 excinfo.match(r'[123]+')
421 """
422 )
423 result = pytester.runpytest()
424 assert result.ret != 0
425
426 exc_msg = "Regex pattern '[[]123[]]+' does not match 'division by zero'."
427 result.stdout.fnmatch_lines([f"E * AssertionError: {exc_msg}"])
428 result.stdout.no_fnmatch_line("*__tracebackhide__ = True*")
429
430 result = pytester.runpytest("--fulltrace")
431 assert result.ret != 0
432 result.stdout.fnmatch_lines(
433 ["*__tracebackhide__ = True*", f"E * AssertionError: {exc_msg}"]
434 )
435
436
437class TestFormattedExcinfo:

Callers

nothing calls this directly

Calls 4

fnmatch_linesMethod · 0.80
no_fnmatch_lineMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected