support using py.test.raises in context manager style

--HG--
branch : trunk
This commit is contained in:
Ronny Pfannschmidt
2010-06-09 10:50:00 +02:00
parent 8ece058256
commit d1c8209875
2 changed files with 66 additions and 6 deletions

View File

@@ -340,6 +340,37 @@ class TestRaises:
except py.test.raises.Exception:
pass
@py.test.mark.skipif('sys.version < "2.5"')
def test_raises_as_contextmanager(self, testdir):
testdir.makepyfile("""
from __future__ import with_statement
import py
def test_simple():
with py.test.raises(ZeroDivisionError) as ctx:
1/0
print ctx.excinfo
assert ctx.excinfo.type is ZeroDivisionError
def test_noraise():
with py.test.raises(py.test.raises.Exception):
with py.test.raises(ValueError):
int()
def test_raise_wrong_exception_passes_by():
with py.test.raises(ZeroDivisionError):
with py.test.raises(ValueError):
1/0
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines([
'*3 passed*',
])
def test_pytest_exit():
try:
py.test.exit("hello")