Coverage for .tox/testcoverage/lib/python2.7/site-packages/_pytest/terminal : 44%

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
""" terminal reporting of the full testing process.
This is a good source for looking at the various reporting hooks. """ EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED
dest="verbose", default=0, help="increase verbosity."), dest="quiet", default=0, help="decrease verbosity."), action="store", dest="reportchars", default=None, metavar="chars", help="show extra test summary info as specified by chars (f)ailed, " "(E)error, (s)skipped, (x)failed, (X)passed (w)pytest-warnings " "(p)passed, (P)passed with output, (a)all except pP.") action="store_true", dest="showlocals", default=False, help="show locals in tracebacks (disabled by default).") action="store", dest="report", default=None, metavar="opts", help="(deprecated, use -r)") action="store", dest="tbstyle", default='auto', choices=['auto', 'long', 'short', 'no', 'line', 'native'], help="traceback print mode (auto/long/short/line/native/no).") action="store_true", default=False, help="don't cut any tracebacks (default is to cut).") action="store", dest="color", default='auto', choices=['yes', 'no', 'auto'], help="color terminal output (yes/no/auto).")
def mywriter(tags, args): msg = " ".join(map(str, args)) reporter.write_line("[traceconfig] " + msg) config.trace.root.setprocessor("pytest:config", mywriter)
py.builtin.print_("DEPRECATED: use -r instead of --report option.", file=sys.stderr) if optvalue: for setting in optvalue.split(","): setting = setting.strip() if setting == "skipped": reportopts += "s" elif setting == "xfailed": reportopts += "x" for char in reportchars: if char not in reportopts and char != 'a': reportopts += char elif char == 'a': reportopts = 'fEsxXw'
elif report.skipped: letter = "s" elif report.failed: letter = "F" if report.when != "call": letter = "f"
self.code = code self.message = message self.nodeid = nodeid self.fslocation = fslocation
file = sys.stdout file)
if self.currentfspath != prefix: self._tw.line() self.currentfspath = prefix self._tw.write(prefix) if extra: self._tw.write(extra, **kwargs) self.currentfspath = -2
self._tw.write(content, **markup)
self._tw.sep(sep, title, **kw)
self._tw.line(msg, **kw)
for line in py.builtin.text(excrepr).split("\n"): self.write_line("INTERNALERROR> " + line) return 1
warnings = self.stats.setdefault("warnings", []) if isinstance(fslocation, tuple): fslocation = "%s:%d" % fslocation warning = WarningReport(code=code, fslocation=fslocation, message=message, nodeid=nodeid) warnings.append(warning)
msg = "PLUGIN registered: %s" % (plugin,) # XXX this event may happen during setup/teardown time # which unfortunately captures our output here # which garbles our output if we use self.write_line self.write_line(msg)
self.stats.setdefault('deselected', []).extend(items)
# ensure that the path is printed before the # 1st test of a module starts running line = self._locationline(nodeid, *location) self.write_ensure_prefix(line, "")
# probably passed setup/teardown else: self._tw.write(letter) else: if isinstance(word, tuple): word, markup = word else: if rep.passed: markup = {'green':True} elif rep.failed: markup = {'red':True} elif rep.skipped: markup = {'yellow':True} line = self._locationline(rep.nodeid, *rep.location) if not hasattr(rep, 'node'): self.write_ensure_prefix(line, word, **markup) #self._tw.write(word, **markup) else: self.ensure_newline() if hasattr(rep, 'node'): self._tw.write("[%s] " % rep.node.gateway.id) self._tw.write(word, **markup) self._tw.write(" " + line) self.currentfspath = -2
self.write("collecting ... ", bold=True)
self.stats.setdefault("error", []).append(report) self.stats.setdefault("skipped", []).append(report) #self.write_fspath_result(report.nodeid, 'E')
return
else: line += " / %d errors" % errors line += " / %d skipped" % skipped else: self.write_line(line)
def pytest_sessionstart(self, session): return verinfo = ".".join(map(str, sys.pypy_version_info[:3])) msg += "[pypy-%s-%s]" % (verinfo, sys.pypy_version_info[3]) pytest.__version__, py.__version__, pluggy.__version__) getattr(self.config.option, 'pastebin', None): msg += " -- " + str(sys.executable) config=self.config, startdir=self.startdir)
lines.append( "plugins: %s" % ", ".join(_plugin_nameversions(plugininfo)))
self._printcollecteditems(session.items) if self.stats.get('failed'): self._tw.sep("!", "collection failures") for rep in self.stats.get('failed'): rep.toterminal(self._tw) return 1 return 0 return #for i, testarg in enumerate(self.config.args): # self.write_line("test path %d: %s" %(i+1, testarg))
# to print out items and their parent collectors # we take care to leave out Instances aka () # because later versions are going to get rid of them anyway if self.config.option.verbose < 0: if self.config.option.verbose < -1: counts = {} for item in items: name = item.nodeid.split('::', 1)[0] counts[name] = counts.get(name, 0) + 1 for name, count in sorted(counts.items()): self._tw.line("%s: %d" % (name, count)) else: for item in items: nodeid = item.nodeid nodeid = nodeid.replace("::()::", "::") self._tw.line(nodeid) return stack = [] indent = "" for item in items: needed_collectors = item.listchain()[1:] # strip root node while stack: if stack == needed_collectors[:len(stack)]: break stack.pop() for col in needed_collectors[len(stack):]: stack.append(col) #if col.name == "()": # continue indent = (len(stack) - 1) * " " self._tw.line("%s%s" % (indent, col))
def pytest_sessionfinish(self, exitstatus): EXIT_OK, EXIT_TESTSFAILED, EXIT_INTERRUPTED, EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED) self._report_keyboardinterrupt() del self._keyboardinterrupt_memo
self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
self._report_keyboardinterrupt()
excrepr = self._keyboardinterrupt_memo msg = excrepr.reprcrash.message self.write_sep("!", msg) if "KeyboardInterrupt" in msg: if self.config.option.fulltrace: excrepr.toterminal(self._tw) else: self._tw.line("to show a full traceback on KeyboardInterrupt use --fulltrace", yellow=True) excrepr.reprcrash.toterminal(self._tw)
def mkrel(nodeid): line = self.config.cwd_relative_nodeid(nodeid) if domain and line.endswith(domain): line = line[:-len(domain)] l = domain.split("[") l[0] = l[0].replace('.', '::') # don't replace '.' in params line += "[".join(l) return line # collect_fspath comes from testid which has a "/"-normalized path
if fspath: res = mkrel(nodeid).replace("::()", "") # parens-normalization if nodeid.split("::")[0] != fspath.replace("\\", "/"): res += " <- " + self.startdir.bestrelpath(fspath) else: res = "[location]" return res + " "
if hasattr(rep, 'location'): fspath, lineno, domain = rep.location return domain else: return "test session" # XXX?
try: return str(rep.longrepr.reprcrash) except AttributeError: try: return str(rep.longrepr)[:50] except AttributeError: return ""
# # summaries for sessionfinish # if not hasattr(x, '_pdbshown'): l.append(x)
warnings = self.stats.get("warnings") if not warnings: return self.write_sep("=", "pytest-warning summary") for w in warnings: self._tw.line("W%s %s %s" % (w.code, w.fslocation, w.message))
reports = self.getreports('passed') if not reports: return self.write_sep("=", "PASSES") for rep in reports: msg = self._getfailureheadline(rep) self.write_sep("_", msg) self._outrep_summary(rep)
self.write_sep("=", "FAILURES") for rep in reports: if self.config.option.tbstyle == "line": line = self._getcrashline(rep) self.write_line(line) else: msg = self._getfailureheadline(rep) markup = {'red': True, 'bold': True} self.write_sep("_", msg, **markup) self._outrep_summary(rep)
self.write_sep("=", "ERRORS") for rep in self.stats['error']: msg = self._getfailureheadline(rep) if not hasattr(rep, 'when'): # collect msg = "ERROR collecting " + msg elif rep.when == "setup": msg = "ERROR at setup of " + msg elif rep.when == "teardown": msg = "ERROR at teardown of " + msg self.write_sep("_", msg) self._outrep_summary(rep)
rep.toterminal(self._tw) for secname, content in rep.sections: self._tw.sep("-", secname) if content[-1:] == "\n": content = content[:-1] self._tw.line(content)
self.write_line(msg, **markup)
l = [] k = self.config.option.keyword if k: l.append("-k%s" % k) m = self.config.option.markexpr if m: l.append("-m %r" % m) if l: self.write_sep("=", "%d tests deselected by %r" % ( len(self.stats['deselected']), " ".join(l)), bold=True)
if v is None: v = sys.version_info try: return "%s.%s.%s-%s-%s" % v except (TypeError, ValueError): return str(v)
else:
"xfailed xpassed warnings error").split() keys.append(key) unknown_key_seen = True
else: line = "no tests ran"
color = 'red' color = 'yellow' else: color = 'yellow'
l = [] for plugin, dist in plugininfo: # gets us name and version! name = '{dist.project_name}-{dist.version}'.format(dist=dist) # questionable convenience, but it keeps things short if name.startswith("pytest-"): name = name[7:] # we decided to print python package names # they can have more than one plugin if name not in l: l.append(name) return l |