Coverage for .tox/testcoverage/lib/python2.7/site-packages/_pytest/runner : 54%

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
""" basic collect and runtest protocol implementations """
'fail' : fail, 'skip' : skip, 'importorskip' : importorskip, 'exit' : exit, }
# # pytest plugin hooks
action="store", type=int, default=None, metavar="N", help="show N slowest setup/test durations (N=0 for all)."),
tr = terminalreporter dlist = [] for replist in tr.stats.values(): for rep in replist: if hasattr(rep, 'duration'): dlist.append(rep) if not dlist: return dlist.sort(key=lambda x: x.duration) dlist.reverse() if not durations: tr.write_sep("=", "slowest test durations") else: tr.write_sep("=", "slowest %s test durations" % durations) dlist = dlist[:durations]
for rep in dlist: nodeid = rep.nodeid.replace("::()::", "::") tr.write_line("%02.2fs %-8s %s" % (rep.duration, rep.when, nodeid))
self.location = location
nodeid=item.nodeid, location=item.location, )
item._initrequest() nextitem=nextitem)) # after all teardown hooks have been called # want funcargs and request info to go away
except Exception: # Store trace info to allow postmortem debugging type, value, tb = sys.exc_info() tb = tb.tb_next # Skip *this* frame sys.last_type = type sys.last_value = value sys.last_traceback = tb del tb # Get rid of it in this namespace raise
# category, shortletter, verbose-word return "error", "E", "ERROR" return "skipped", "s", "SKIPPED" else:
# # Implementation
hook.pytest_exception_interact(node=item, call=call, report=report)
hasattr(report, "wasxfail") or call.excinfo.errisinstance(skip.Exception) or call.excinfo.errisinstance(bdb.BdbQuit))
""" Result/Exception info a function invocation. """ #: None or ExceptionInfo object. #: context of invocation: one of "setup", "call", #: "teardown", "memocollect" except KeyboardInterrupt: self.stop = time() raise except: self.excinfo = ExceptionInfo()
if self.excinfo: status = "exception: %s" % str(self.excinfo.value) else: status = "result: %r" % (self.result,) return "<CallInfo when=%r %s>" % (self.when, status)
try: return node._slaveinfocache except AttributeError: d = node.slaveinfo ver = "%s.%s.%s" % d['version_info'][:3] node._slaveinfocache = s = "[%s] %s -- Python %s %s" % ( d['id'], d['sysplatform'], ver, d['executable']) return s
self.__dict__.update(kw)
if hasattr(self, 'node'): out.line(getslaveinfoline(self.node))
longrepr = self.longrepr if longrepr is None: return
if hasattr(longrepr, 'toterminal'): longrepr.toterminal(out) else: try: out.line(longrepr) except UnicodeEncodeError: out.line("<unprintable longrepr>")
for name, content in self.sections: if name.startswith(prefix): yield prefix, content
def fspath(self): return self.nodeid.split("::")[0]
else: if not isinstance(excinfo, ExceptionInfo): outcome = "failed" longrepr = excinfo elif excinfo.errisinstance(pytest.skip.Exception): outcome = "skipped" r = excinfo._getreprcrash() longrepr = (str(r.path), r.lineno, r.message) else: outcome = "failed" if call.when == "call": longrepr = item.repr_failure(excinfo) else: # exception in setup or teardown longrepr = item._repr_failure_py(excinfo, style=item.config.option.tbstyle) sections.append(("Captured %s %s" %(key, rwhen), content)) keywords, outcome, longrepr, when, sections, duration)
""" Basic test report object (also used for setup and teardown calls if they fail). """ longrepr, when, sections=(), duration=0, **extra): #: normalized collection node id
#: a (filesystempath, lineno, domaininfo) tuple indicating the #: actual location of a test item - it might be different from the #: collected one e.g. if a method is inherited from a different module.
#: a name -> value dictionary containing all keywords and #: markers associated with a test invocation.
#: test outcome, always one of "passed", "failed", "skipped".
#: None or a failure representation.
#: one of 'setup', 'call', 'teardown' to indicate runtest phase.
#: list of (secname, data) extra information which needs to #: marshallable
#: time it took to run just the test
return "<TestReport %r when=%r outcome=%r>" % ( self.nodeid, self.when, self.outcome)
self.longrepr = longrepr self.sections = [] self.__dict__.update(extra)
else: from _pytest import nose skip_exceptions = (Skipped,) + nose.get_skip_exceptions() if call.excinfo.errisinstance(skip_exceptions): outcome = "skipped" r = collector._repr_failure_py(call.excinfo, "line").reprcrash longrepr = (str(r.path), r.lineno, r.message) else: outcome = "failed" errorinfo = collector.repr_failure(call.excinfo) if not hasattr(errorinfo, "toterminal"): errorinfo = CollectErrorRepr(errorinfo) longrepr = errorinfo getattr(call, 'result', None))
sections=(), **extra):
def location(self): return (self.fspath, None, self.fspath)
return "<CollectReport %r lenresult=%s outcome=%r>" % ( self.nodeid, len(self.result), self.outcome)
self.longrepr = msg out.line(self.longrepr, red=True)
""" shared state for setting up/tearing down test items or collectors. """
""" attach a finalizer to the given colitem. if colitem is None, this will add a finalizer that is called at the end of teardown_all(). """ #assert colitem in self.stack # some unit tests don't setup stack :/
except Exception: # XXX Only first exception will be seen by user, # ideally all should be reported. if exc is None: exc = sys.exc_info() py.builtin._reraise(*exc)
or isinstance(colitem, tuple)
self._pop_and_teardown() self._teardown_with_finalization(key)
""" setup objects along the collector chain to the test-method and teardown previously setup objects."""
# check if the last collection node has raised an error py.builtin._reraise(*col._prepare_exc) except Exception: col._prepare_exc = sys.exc_info() raise
ihook.pytest_exception_interact(node=collector, call=call, report=rep)
# ============================================================= # Test OutcomeExceptions and helpers for creating them.
""" OutcomeException and its subclass instances indicate and contain info about test and collection outcomes. """ Exception.__init__(self, msg) self.msg = msg self.pytrace = pytrace
if self.msg: val = self.msg if isinstance(val, bytes): val = py._builtin._totext(val, errors='replace') return val return "<%s instance>" %(self.__class__.__name__,)
# XXX hackish: on 3k we fake to live in the builtins # in order to have Skipped exception printing shorter/nicer
""" raised from an explicit call to pytest.fail() """
""" raised for immediate program exits (no tracebacks/summaries)""" self.msg = msg KeyboardInterrupt.__init__(self, msg)
# exposed helper methods
""" exit testing process as if KeyboardInterrupt was triggered. """ __tracebackhide__ = True raise Exit(msg)
""" skip an executing test with the given message. Note: it's usually better to use the pytest.mark.skipif marker to declare a test to be skipped under certain conditions like mismatching platforms or dependencies. See the pytest_skipping plugin for details. """ __tracebackhide__ = True raise Skipped(msg=msg)
""" explicitly fail an currently-executing test with the given Message.
:arg pytrace: if false the msg represents the full failure information and no python traceback will be reported. """ __tracebackhide__ = True raise Failed(msg=msg, pytrace=pytrace)
""" return imported module if it has at least "minversion" as its __version__ attribute. If no minversion is specified the a skip is only triggered if the module can not be imported. """ __tracebackhide__ = True compile(modname, '', 'eval') # to catch syntaxerrors try: __import__(modname) except ImportError: skip("could not import %r" %(modname,)) mod = sys.modules[modname] if minversion is None: return mod verattr = getattr(mod, '__version__', None) if minversion is not None: try: from pkg_resources import parse_version as pv except ImportError: skip("we have a required version for %r but can not import " "no pkg_resources to parse version strings." %(modname,)) if verattr is None or pv(verattr) < pv(minversion): skip("module %r has __version__ %r, required is: %r" %( modname, verattr, minversion)) return mod
|