[py-svn] py-trunk commit e4584264f648: implement and naively test the native traceback style
mailer at bitbucket.org
mailer at bitbucket.org
Wed Sep 8 16:55:36 CEST 2010
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
# Date 1283940036 -7200
# Node ID e4584264f64870c3fe36a83f401a6a8bb2bd7e13
# Parent 04b17770932e208406d8bf0d4ba890c6a61da614
implement and naively test the native traceback style
--- a/testing/code/test_excinfo.py
+++ b/testing/code/test_excinfo.py
@@ -700,3 +700,12 @@ raise ValueError()
repr = excinfo.getrepr(**reproptions)
repr.toterminal(tw)
assert tw.stringio.getvalue()
+
+
+ def test_native_style(self):
+ excinfo = self.excinfo_from_exec("""
+ assert 0
+ """)
+ repr = excinfo.getrepr(style='native')
+ assert repr.startswith('Traceback (most recent call last):\n File')
+ assert repr.endswith('\n assert 0\nAssertionError: assert 0\n')
--- a/py/_code/code.py
+++ b/py/_code/code.py
@@ -354,9 +354,17 @@ class ExceptionInfo(object):
abspath=False, tbfilter=True, funcargs=False):
""" return str()able representation of this exception info.
showlocals: show locals per traceback entry
- style: long|short|no traceback style
+ style: long|short|no|native traceback style
tbfilter: hide entries (where __tracebackhide__ is true)
"""
+ if style == 'native':
+ import traceback
+ return ''.join(traceback.format_exception(
+ self.type,
+ self.value,
+ self.traceback[0]._rawentry,
+ ))
+
fmt = FormattedExcinfo(showlocals=showlocals, style=style,
abspath=abspath, tbfilter=tbfilter, funcargs=funcargs)
return fmt.repr_excinfo(self)
--- a/py/_plugin/pytest_terminal.py
+++ b/py/_plugin/pytest_terminal.py
@@ -22,7 +22,7 @@ def pytest_addoption(parser):
help="(deprecated, use -r)")
group._addoption('--tb', metavar="style",
action="store", dest="tbstyle", default='long',
- type="choice", choices=['long', 'short', 'no', 'line'],
+ type="choice", choices=['long', 'short', 'no', 'line', 'native'],
help="traceback print mode (long/short/line/no).")
group._addoption('--fulltrace',
action="store_true", dest="fulltrace", default=False,
More information about the pytest-commit
mailing list