[svn r57790] Reintroduce the --tb option. Add test.

--HG--
branch : trunk
This commit is contained in:
arigo 2008-09-03 10:15:44 +02:00
parent d83db97806
commit b52c58159f
4 changed files with 38 additions and 5 deletions

View File

@ -243,9 +243,10 @@ class ReprTraceback(Repr):
def toterminal(self, tw):
sepok = False
for entry in self.reprentries:
if sepok and self.style == "long":
tw.sep(self.entrysep)
tw.line("")
if self.style == "long":
if sepok:
tw.sep(self.entrysep)
tw.line("")
sepok = True
entry.toterminal(tw)
if self.extraline:

View File

@ -268,7 +268,8 @@ class Node(object):
def _repr_failure_py(self, excinfo, outerr):
excinfo.traceback = self._prunetraceback(excinfo.traceback)
repr = excinfo.getrepr(funcargs=True,
showlocals=self._config.option.showlocals)
showlocals=self._config.option.showlocals,
style=self._config.option.tbstyle)
for secname, content in zip(["out", "err"], outerr):
if content:
repr.addsection("Captured std%s" % secname, content.rstrip())

View File

@ -156,7 +156,7 @@ class TerminalReporter(BaseReporter):
#
def summary_failures(self):
if self._failed:
if self._failed and self.config.option.tbstyle != "no":
self.write_sep("=", "FAILURES")
for ev in self._failed:
self.write_sep("_")

View File

@ -161,3 +161,34 @@ class TestTerminal(InlineCollection):
"*waiting*",
"*%s*" % (modcol._config.topdir),
])
def test_tb_option(self):
for tbopt in ["no", "short", "long"]:
print 'testing --tb=%s...' % tbopt
modcol = self.getmodulecol("""
import py
def g():
raise IndexError
def test_func():
print 6*7
g() # --calling--
""", configargs=("--tb=%s" % tbopt,), withsession=True)
stringio = py.std.cStringIO.StringIO()
rep = TerminalReporter(modcol._config, file=stringio)
rep.processevent(event.TestrunStart())
for item in self.session.genitems([modcol]):
ev = basic_run_report(item)
rep.processevent(ev)
rep.processevent(event.TestrunFinish())
s = popvalue(stringio)
if tbopt == "long":
assert 'print 6*7' in s
else:
assert 'print 6*7' not in s
if tbopt != "no":
assert '--calling--' in s
assert 'IndexError' in s
else:
assert 'FAILURES' not in s
assert '--calling--' not in s
assert 'IndexError' not in s