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

Method test_raises_as_contextmanager

testing/python/raises.py:54–80  ·  view source on GitHub ↗
(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

52 raise E()
53
54 def test_raises_as_contextmanager(self, pytester: Pytester) -> None:
55 pytester.makepyfile(
56 """
57 import pytest
58 import _pytest._code
59
60 def test_simple():
61 with pytest.raises(ZeroDivisionError) as excinfo:
62 assert isinstance(excinfo, _pytest._code.ExceptionInfo)
63 1/0
64 print(excinfo)
65 assert excinfo.type == ZeroDivisionError
66 assert isinstance(excinfo.value, ZeroDivisionError)
67
68 def test_noraise():
69 with pytest.raises(pytest.raises.Exception):
70 with pytest.raises(ValueError):
71 int()
72
73 def test_raise_wrong_exception_passes_by():
74 with pytest.raises(ZeroDivisionError):
75 with pytest.raises(ValueError):
76 1/0
77 """
78 )
79 result = pytester.runpytest()
80 result.stdout.fnmatch_lines(["*3 passed*"])
81
82 def test_does_not_raise(self, pytester: Pytester) -> None:
83 pytester.makepyfile(

Callers

nothing calls this directly

Calls 3

fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected