From b52c58159fc4481b9f78c8c1901ea4717cfce4bd Mon Sep 17 00:00:00 2001 From: arigo Date: Wed, 3 Sep 2008 10:15:44 +0200 Subject: [PATCH] [svn r57790] Reintroduce the --tb option. Add test. --HG-- branch : trunk --- py/code/excinfo.py | 7 +++--- py/test/collect.py | 3 ++- py/test/report/terminal.py | 2 +- py/test/report/testing/test_terminal.py | 31 +++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/py/code/excinfo.py b/py/code/excinfo.py index 06a47bbc7..edd30fece 100644 --- a/py/code/excinfo.py +++ b/py/code/excinfo.py @@ -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: diff --git a/py/test/collect.py b/py/test/collect.py index f5ef307ad..231cfc2d1 100644 --- a/py/test/collect.py +++ b/py/test/collect.py @@ -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()) diff --git a/py/test/report/terminal.py b/py/test/report/terminal.py index 5b77e23a3..c815f208d 100644 --- a/py/test/report/terminal.py +++ b/py/test/report/terminal.py @@ -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("_") diff --git a/py/test/report/testing/test_terminal.py b/py/test/report/testing/test_terminal.py index 6d6ebf1c7..52dd952cb 100644 --- a/py/test/report/testing/test_terminal.py +++ b/py/test/report/testing/test_terminal.py @@ -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