refine unittest support to also work with twisted trial test cases better by
introducing a slightly hackish way to report a failure upstream
This commit is contained in:
+34
-2
@@ -33,16 +33,40 @@ class UnitTestCase(pytest.Class):
|
||||
meth()
|
||||
|
||||
class TestCaseFunction(pytest.Function):
|
||||
_excinfo = None
|
||||
def setup(self):
|
||||
pass
|
||||
def teardown(self):
|
||||
pass
|
||||
def startTest(self, testcase):
|
||||
pass
|
||||
|
||||
def _addexcinfo(self, rawexcinfo):
|
||||
#__tracebackhide__ = True
|
||||
assert rawexcinfo
|
||||
try:
|
||||
self._excinfo = py.code.ExceptionInfo(rawexcinfo)
|
||||
except TypeError:
|
||||
try:
|
||||
try:
|
||||
l = py.std.traceback.format_exception(*rawexcinfo)
|
||||
l.insert(0, "NOTE: Incompatible Exception Representation, "
|
||||
"displaying natively:\n\n")
|
||||
pytest.fail("".join(l), pytrace=False)
|
||||
except (pytest.fail.Exception, KeyboardInterrupt):
|
||||
raise
|
||||
except:
|
||||
pytest.fail("ERROR: Unknown Incompatible Exception "
|
||||
"representation:\n%r" %(rawexcinfo,), pytrace=False)
|
||||
except pytest.fail.Exception:
|
||||
self._excinfo = py.code.ExceptionInfo()
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
|
||||
def addError(self, testcase, rawexcinfo):
|
||||
py.builtin._reraise(*rawexcinfo)
|
||||
self._addexcinfo(rawexcinfo)
|
||||
def addFailure(self, testcase, rawexcinfo):
|
||||
py.builtin._reraise(*rawexcinfo)
|
||||
self._addexcinfo(rawexcinfo)
|
||||
def addSuccess(self, testcase):
|
||||
pass
|
||||
def stopTest(self, testcase):
|
||||
@@ -50,3 +74,11 @@ class TestCaseFunction(pytest.Function):
|
||||
def runtest(self):
|
||||
testcase = self.parent.obj(self.name)
|
||||
testcase(result=self)
|
||||
|
||||
@pytest.mark.tryfirst
|
||||
def pytest_runtest_makereport(item, call):
|
||||
if isinstance(item, TestCaseFunction):
|
||||
if item._excinfo:
|
||||
call.excinfo = item._excinfo
|
||||
item._excinfo = None
|
||||
del call.result
|
||||
|
||||
Reference in New Issue
Block a user