Coverage for .tox/testcoverage/lib/python2.7/site-packages/_pytest/unittest : 49%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" discovery and running of std-library "unittest" style tests. """
# for transfering markers
# has unittest been imported and is obj a subclass of its TestCase? # yes, so let's collect it
# marker for fixturemanger.getfixtureinfo() # to declare that our children do not support funcargs
return # skipped
return
runtest = getattr(self.obj, 'runTest', None) if runtest is not None: ut = sys.modules.get("twisted.trial.unittest", None) if ut is None or runtest != ut.TestCase.runTest: yield TestCaseFunction('runTest', parent=self)
self._testcase.setup_method(self._obj)
""" The @unittest.skip decorator calls functools.wraps(self._testcase) The call to functools.wraps() fails unless self._testcase has a __name__ attribute. This is usually automatically supplied if the test is a function or method, but we need to add manually here.
See issue #1169 """
self._testcase.teardown_method(self._obj)
# unwrap potential exception info (see twisted trial support below) rawexcinfo = getattr(rawexcinfo, '_rawexcinfo', rawexcinfo) try: excinfo = _pytest._code.ExceptionInfo(rawexcinfo) except TypeError: try: try: l = 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 KeyboardInterrupt: raise except pytest.fail.Exception: excinfo = _pytest._code.ExceptionInfo() self.__dict__.setdefault('_excinfo', []).append(excinfo)
self._addexcinfo(rawexcinfo) self._addexcinfo(rawexcinfo)
try: pytest.skip(reason) except pytest.skip.Exception: self._evalskip = MarkEvaluator(self, 'SkipTest') self._evalskip.result = True self._addexcinfo(sys.exc_info())
try: pytest.xfail(str(reason)) except pytest.xfail.Exception: self._addexcinfo(sys.exc_info())
self._unexpectedsuccess = reason
pytest.Function._prunetraceback(self, excinfo) traceback = excinfo.traceback.filter( lambda x:not x.frame.f_globals.get('__unittest')) if traceback: excinfo.traceback = traceback
def pytest_runtest_makereport(item, call): call.excinfo = item._excinfo.pop(0) try: del call.result except AttributeError: pass
# twisted trial support
def pytest_runtest_protocol(item): 'twisted.trial.unittest' in sys.modules: ut = sys.modules['twisted.python.failure'] Failure__init__ = ut.Failure.__init__ check_testcase_implements_trial_reporter() def excstore(self, exc_value=None, exc_type=None, exc_tb=None, captureVars=None): if exc_value is None: self._rawexcinfo = sys.exc_info() else: if exc_type is None: exc_type = type(exc_value) self._rawexcinfo = (exc_type, exc_value, exc_tb) try: Failure__init__(self, exc_value, exc_type, exc_tb, captureVars=captureVars) except TypeError: Failure__init__(self, exc_value, exc_type, exc_tb) ut.Failure.__init__ = excstore yield ut.Failure.__init__ = Failure__init__ else:
if done: return from zope.interface import classImplements from twisted.trial.itrial import IReporter classImplements(TestCaseFunction, IReporter) done.append(1) |