document and refine py.test.fail helper and strike superflous ExceptionFailure class
refine builtin organisation and start a new doc
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import py, sys
|
||||
import pytest, py, sys
|
||||
from pytest.plugin import python as funcargs
|
||||
|
||||
class TestModule:
|
||||
@@ -1118,3 +1118,60 @@ def test_show_funcarg(testdir):
|
||||
"*temporary directory*",
|
||||
]
|
||||
)
|
||||
|
||||
class TestRaises:
|
||||
def test_raises(self):
|
||||
source = "int('qwe')"
|
||||
excinfo = py.test.raises(ValueError, source)
|
||||
code = excinfo.traceback[-1].frame.code
|
||||
s = str(code.fullsource)
|
||||
assert s == source
|
||||
|
||||
def test_raises_exec(self):
|
||||
py.test.raises(ValueError, "a,x = []")
|
||||
|
||||
def test_raises_syntax_error(self):
|
||||
py.test.raises(SyntaxError, "qwe qwe qwe")
|
||||
|
||||
def test_raises_function(self):
|
||||
py.test.raises(ValueError, int, 'hello')
|
||||
|
||||
def test_raises_callable_no_exception(self):
|
||||
class A:
|
||||
def __call__(self):
|
||||
pass
|
||||
try:
|
||||
py.test.raises(ValueError, A())
|
||||
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 excinfo:
|
||||
assert isinstance(excinfo, py.code.ExceptionInfo)
|
||||
1/0
|
||||
print (excinfo)
|
||||
assert excinfo.type == 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*',
|
||||
])
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class TestWithFunctionIntegration:
|
||||
assert lines[0].startswith("S ")
|
||||
assert lines[0].endswith("test_collection_skip.py")
|
||||
assert lines[1].startswith(" ")
|
||||
assert lines[1].endswith("test_collection_skip.py:1: Skipped: 'hello'")
|
||||
assert lines[1].endswith("test_collection_skip.py:1: Skipped: hello")
|
||||
|
||||
lines = self.getresultlog(testdir, fail)
|
||||
assert lines
|
||||
|
||||
@@ -319,61 +319,6 @@ def test_runtest_in_module_ordering(testdir):
|
||||
"*2 passed*"
|
||||
])
|
||||
|
||||
class TestRaises:
|
||||
def test_raises(self):
|
||||
source = "int('qwe')"
|
||||
excinfo = py.test.raises(ValueError, source)
|
||||
code = excinfo.traceback[-1].frame.code
|
||||
s = str(code.fullsource)
|
||||
assert s == source
|
||||
|
||||
def test_raises_exec(self):
|
||||
py.test.raises(ValueError, "a,x = []")
|
||||
|
||||
def test_raises_syntax_error(self):
|
||||
py.test.raises(SyntaxError, "qwe qwe qwe")
|
||||
|
||||
def test_raises_function(self):
|
||||
py.test.raises(ValueError, int, 'hello')
|
||||
|
||||
def test_raises_callable_no_exception(self):
|
||||
class A:
|
||||
def __call__(self):
|
||||
pass
|
||||
try:
|
||||
py.test.raises(ValueError, A())
|
||||
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 excinfo:
|
||||
assert isinstance(excinfo, py.code.ExceptionInfo)
|
||||
1/0
|
||||
print (excinfo)
|
||||
assert excinfo.type == 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:
|
||||
|
||||
@@ -417,7 +417,7 @@ def test_skipped_reasons_functional(testdir):
|
||||
result.stdout.fnmatch_lines([
|
||||
"*test_two.py S",
|
||||
"*test_one.py ss",
|
||||
"*SKIP*3*conftest.py:3: 'test'",
|
||||
"*SKIP*3*conftest.py:3: test",
|
||||
])
|
||||
assert result.ret == 0
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ class TestCollectonly:
|
||||
assert len(cols) == 0
|
||||
linecomp.assert_contains_lines("""
|
||||
<Module 'test_collectonly_skipped_module.py'>
|
||||
!!! Skipped: 'nomod' !!!
|
||||
!!! Skipped: nomod !!!
|
||||
""")
|
||||
|
||||
def test_collectonly_failed_module(self, testdir, linecomp):
|
||||
|
||||
Reference in New Issue
Block a user