teach trial support code to throw separate errors/failures for setup/call/teardown
This commit is contained in:
parent
ff27d299cc
commit
10d4544267
|
@ -47,7 +47,7 @@ class TestCaseFunction(pytest.Function):
|
|||
# unwrap potential exception info (see twisted trial support below)
|
||||
rawexcinfo = getattr(rawexcinfo, '_rawexcinfo', rawexcinfo)
|
||||
try:
|
||||
self._excinfo = py.code.ExceptionInfo(rawexcinfo)
|
||||
excinfo = py.code.ExceptionInfo(rawexcinfo)
|
||||
except TypeError:
|
||||
try:
|
||||
try:
|
||||
|
@ -63,7 +63,8 @@ class TestCaseFunction(pytest.Function):
|
|||
except KeyboardInterrupt:
|
||||
raise
|
||||
except pytest.fail.Exception:
|
||||
self._excinfo = py.code.ExceptionInfo()
|
||||
excinfo = py.code.ExceptionInfo()
|
||||
self.__dict__.setdefault('_excinfo', []).append(excinfo)
|
||||
|
||||
def addError(self, testcase, rawexcinfo):
|
||||
self._addexcinfo(rawexcinfo)
|
||||
|
@ -80,9 +81,8 @@ class TestCaseFunction(pytest.Function):
|
|||
@pytest.mark.tryfirst
|
||||
def pytest_runtest_makereport(item, call):
|
||||
if isinstance(item, TestCaseFunction):
|
||||
if item._excinfo:
|
||||
call.excinfo = item._excinfo
|
||||
item._excinfo = None
|
||||
if hasattr(item, '_excinfo') and item._excinfo:
|
||||
call.excinfo = item._excinfo.pop(0)
|
||||
del call.result
|
||||
|
||||
# twisted trial support
|
||||
|
|
|
@ -183,11 +183,9 @@ def test_testcase_totally_incompatible_exception_info(testdir):
|
|||
pass
|
||||
""")
|
||||
item.addError(None, 42)
|
||||
excinfo = item._excinfo
|
||||
excinfo = item._excinfo.pop(0)
|
||||
assert 'ERROR: Unknown Incompatible' in str(excinfo.getrepr())
|
||||
|
||||
|
||||
|
||||
class TestTrialUnittest:
|
||||
def setup_class(cls):
|
||||
pytest.importorskip("twisted.trial.unittest")
|
||||
|
@ -225,6 +223,7 @@ class TestTrialUnittest:
|
|||
"*3 skipped*2 xfail*",
|
||||
])
|
||||
|
||||
@pytest.mark.xfail(reason="fijal needs add checks")
|
||||
def test_trial_error(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
from twisted.trial.unittest import TestCase
|
||||
|
@ -262,6 +261,7 @@ class TestTrialUnittest:
|
|||
# will crash both at test time and at teardown
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
assert 0
|
||||
|
||||
def test_trial_pdb(self, testdir):
|
||||
p = testdir.makepyfile("""
|
||||
|
@ -275,6 +275,46 @@ class TestTrialUnittest:
|
|||
child.expect("hellopdb")
|
||||
child.sendeof()
|
||||
|
||||
def test_trial_setup_failure_is_shown(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
from twisted.trial import unittest
|
||||
import pytest
|
||||
class TC(unittest.TestCase):
|
||||
def setUp(self):
|
||||
assert 0, "down1"
|
||||
def test_method(self):
|
||||
print ("never42")
|
||||
xyz
|
||||
""")
|
||||
result = testdir.runpytest("-s")
|
||||
assert result.ret == 1
|
||||
result.stdout.fnmatch_lines([
|
||||
"*setUp*",
|
||||
"*assert 0*down1*",
|
||||
"*1 failed*",
|
||||
])
|
||||
assert 'never42' not in result.stdout.str()
|
||||
|
||||
def test_trial_teardown_and_test_failure(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
from twisted.trial import unittest
|
||||
import pytest
|
||||
class TC(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
assert 0, "down1"
|
||||
def test_method(self):
|
||||
assert False, "down2"
|
||||
""")
|
||||
result = testdir.runpytest("-s")
|
||||
assert result.ret == 1
|
||||
result.stdout.fnmatch_lines([
|
||||
"*tearDown*",
|
||||
"*assert 0*",
|
||||
"*test_method*",
|
||||
"*assert False*",
|
||||
"*1 failed*1 error*",
|
||||
])
|
||||
|
||||
def test_djangolike_testcase(testdir):
|
||||
# contributed from Morten Breekevold
|
||||
testdir.makepyfile("""
|
||||
|
|
Loading…
Reference in New Issue