closes #67 new super-short traceback-printing option: "--tb=line" will print a single line for each failing (python) test indicating its filename, lineno and the failure value
--HG-- branch : trunk
This commit is contained in:
parent
b18ab6e03b
commit
98608611af
|
@ -1,6 +1,7 @@
|
|||
Changes between 1.2.1 and 1.2.0
|
||||
=====================================
|
||||
|
||||
- fix issue67: new super-short traceback-printing option: "--tb=line" will print a single line for each failing (python) test indicating its filename, lineno and the failure value
|
||||
- fix issue78: always call python-level teardown functions even if the
|
||||
according setup failed - but make sure that setup is called repeatedly
|
||||
and no teardown if the setup raises a Skipped (as sone by py.test.skip()).
|
||||
|
|
|
@ -18,8 +18,8 @@ def pytest_addoption(parser):
|
|||
help="show more info, valid: skipped,xfailed")
|
||||
group._addoption('--tb', metavar="style",
|
||||
action="store", dest="tbstyle", default='long',
|
||||
type="choice", choices=['long', 'short', 'no'],
|
||||
help="traceback verboseness (long/short/no).")
|
||||
type="choice", choices=['long', 'short', 'no', 'line'],
|
||||
help="traceback print mode (long/short/line/no).")
|
||||
group._addoption('--fulltrace',
|
||||
action="store_true", dest="fulltrace", default=False,
|
||||
help="don't cut any tracebacks (default is to cut).")
|
||||
|
@ -272,15 +272,18 @@ class TerminalReporter:
|
|||
if failreports:
|
||||
self.write_sep("#", "LOOPONFAILING", red=True)
|
||||
for report in failreports:
|
||||
try:
|
||||
loc = report.longrepr.reprcrash
|
||||
except AttributeError:
|
||||
loc = str(report.longrepr)[:50]
|
||||
loc = self._getcrashline(report)
|
||||
self.write_line(loc, red=True)
|
||||
self.write_sep("#", "waiting for changes")
|
||||
for rootdir in rootdirs:
|
||||
self.write_line("### Watching: %s" %(rootdir,), bold=True)
|
||||
|
||||
def _getcrashline(self, report):
|
||||
try:
|
||||
return report.longrepr.reprcrash
|
||||
except AttributeError:
|
||||
return str(report.longrepr)[:50]
|
||||
|
||||
def _reportinfoline(self, item):
|
||||
collect_fspath = self._getfspath(item)
|
||||
fspath, lineno, msg = self._getreportinfo(item)
|
||||
|
@ -333,13 +336,18 @@ class TerminalReporter:
|
|||
#
|
||||
|
||||
def summary_failures(self):
|
||||
if 'failed' in self.stats and self.config.option.tbstyle != "no":
|
||||
tbstyle = self.config.getvalue("tbstyle")
|
||||
if 'failed' in self.stats and tbstyle != "no":
|
||||
self.write_sep("=", "FAILURES")
|
||||
for rep in self.stats['failed']:
|
||||
msg = self._getfailureheadline(rep)
|
||||
self.write_sep("_", msg)
|
||||
self.write_platinfo(rep)
|
||||
rep.toterminal(self._tw)
|
||||
if tbstyle == "line":
|
||||
line = self._getcrashline(rep)
|
||||
self.write_line(line)
|
||||
else:
|
||||
msg = self._getfailureheadline(rep)
|
||||
self.write_sep("_", msg)
|
||||
self.write_platinfo(rep)
|
||||
rep.toterminal(self._tw)
|
||||
|
||||
def summary_errors(self):
|
||||
if 'error' in self.stats and self.config.option.tbstyle != "no":
|
||||
|
|
|
@ -153,6 +153,26 @@ class TestTerminal:
|
|||
assert '--calling--' not in s
|
||||
assert 'IndexError' not in s
|
||||
|
||||
def test_tb_crashline(self, testdir, option):
|
||||
p = testdir.makepyfile("""
|
||||
import py
|
||||
def g():
|
||||
raise IndexError
|
||||
def test_func1():
|
||||
print (6*7)
|
||||
g() # --calling--
|
||||
def test_func2():
|
||||
assert 0, "hello"
|
||||
""")
|
||||
result = testdir.runpytest("--tb=line")
|
||||
bn = p.basename
|
||||
result.stdout.fnmatch_lines([
|
||||
"*%s:3: IndexError*" % bn,
|
||||
"*%s:8: AssertionError: hello*" % bn,
|
||||
])
|
||||
s = result.stdout.str()
|
||||
assert "def test_func2" not in s
|
||||
|
||||
def test_show_path_before_running_test(self, testdir, linecomp):
|
||||
item = testdir.getitem("def test_func(): pass")
|
||||
tr = TerminalReporter(item.config, file=linecomp.stringio)
|
||||
|
|
Loading…
Reference in New Issue