fix some more trial/unittest related bits, particularly allow todo/skip items,
now we can run a large fraction of twisted's own test suite, mostly not those that depend on the exact Failure() semantics (e.g. frame objects not being around after gc.collect() but py.test kills them only slightly later anyway)
This commit is contained in:
parent
1df0eaa387
commit
f6894ce550
|
@ -37,6 +37,12 @@ class UnitTestCase(pytest.Class):
|
|||
class TestCaseFunction(pytest.Function):
|
||||
_excinfo = None
|
||||
|
||||
def __init__(self, name, parent):
|
||||
super(TestCaseFunction, self).__init__(name, parent)
|
||||
if hasattr(self._obj, 'todo'):
|
||||
getattr(self._obj, 'im_func', self._obj).xfail = \
|
||||
pytest.mark.xfail(reason=str(self._obj.todo))
|
||||
|
||||
def setup(self):
|
||||
self._testcase = self.parent.obj(self.name)
|
||||
self._obj = getattr(self._testcase, self.name)
|
||||
|
@ -77,6 +83,18 @@ class TestCaseFunction(pytest.Function):
|
|||
self._addexcinfo(rawexcinfo)
|
||||
def addFailure(self, testcase, rawexcinfo):
|
||||
self._addexcinfo(rawexcinfo)
|
||||
def addSkip(self, testcase, reason):
|
||||
try:
|
||||
pytest.skip(reason)
|
||||
except pytest.skip.Exception:
|
||||
self._addexcinfo(sys.exc_info())
|
||||
def addExpectedFailure(self, testcase, rawexcinfo, reason):
|
||||
try:
|
||||
pytest.xfail(str(reason))
|
||||
except pytest.xfail.Exception:
|
||||
self._addexcinfo(sys.exc_info())
|
||||
def addUnexpectedSuccess(self, testcase, reason):
|
||||
pass
|
||||
def addSuccess(self, testcase):
|
||||
pass
|
||||
def stopTest(self, testcase):
|
||||
|
|
|
@ -251,6 +251,17 @@ class TestTrialUnittest:
|
|||
assert 0
|
||||
def test_hello4(self):
|
||||
pytest.xfail("i2wanto")
|
||||
def test_trial_skip(self):
|
||||
pass
|
||||
test_trial_skip.skip = "trialselfskip"
|
||||
|
||||
def test_trial_todo(self):
|
||||
assert 0
|
||||
test_trial_todo.todo = "mytodo"
|
||||
|
||||
def test_trial_todo_success(self):
|
||||
pass
|
||||
test_trial_todo_success.todo = "mytodo"
|
||||
|
||||
class TC2(unittest.TestCase):
|
||||
def setup_class(cls):
|
||||
|
@ -261,15 +272,16 @@ class TestTrialUnittest:
|
|||
result = testdir.runpytest("-rxs")
|
||||
assert result.ret == 0
|
||||
result.stdout.fnmatch_lines_random([
|
||||
"*XFAIL*test_trial_todo*",
|
||||
"*trialselfskip*",
|
||||
"*skip_in_setup_class*",
|
||||
"*iwanto*",
|
||||
"*i2wanto*",
|
||||
"*sys.version_info*",
|
||||
"*skip_in_method*",
|
||||
"*3 skipped*2 xfail*",
|
||||
"*4 skipped*3 xfail*1 xpass*",
|
||||
])
|
||||
|
||||
@pytest.mark.xfail(reason="fijal needs add checks")
|
||||
def test_trial_error(self, testdir):
|
||||
testdir.makepyfile("""
|
||||
from twisted.trial.unittest import TestCase
|
||||
|
@ -307,7 +319,18 @@ class TestTrialUnittest:
|
|||
# will crash both at test time and at teardown
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
assert 0
|
||||
result.stdout.fnmatch_lines([
|
||||
"*ERRORS*",
|
||||
"*DelayedCalls*",
|
||||
"*test_four*",
|
||||
"*NameError*crash*",
|
||||
"*test_one*",
|
||||
"*NameError*crash*",
|
||||
"*test_three*",
|
||||
"*DelayedCalls*",
|
||||
"*test_two*",
|
||||
"*crash*",
|
||||
])
|
||||
|
||||
def test_trial_pdb(self, testdir):
|
||||
p = testdir.makepyfile("""
|
||||
|
|
Loading…
Reference in New Issue