[TIP] Context Sensitive Traceback in nosetests Error
Kamal Ahmed
kamal2222ahmed at yahoo.com
Wed Jul 13 13:39:12 PDT 2011
Hi,
In order to append sys.argv to ERROR, i have:
"setup.py"
-------------------------
import sys
try:
import ez_setup
ez_setup.use_setuptools()
except ImportError:
pass
from setuptools import setup
setup(
name='Context Traceback plugin',
version='0.5',
author='Kamal Ahmed',
author_email = 'k.a at ts.com',
description = 'Append argv to Traceback plugin',
license = '2011',
py_modules = ['plugin_argv'],
entry_points = {
'nose.plugins': [
'plugin_argv= plugin_argv:pluginargv'
]
}
)
-------------------------------------------------
"plugin_argv.py"
-------------------------------------------------
"""
This plugin adds argv to tracebacks
"""
import os
from nose.plugins import Plugin
from nose.inspector import inspect_traceback
class pluginargv(Plugin):
"""
Plugin that appends argv to Traceback.
"""
score = 600 # before capture
def options(self, parser, env=os.environ):
parser.add_option(
"--argv-append",
action="store_true",
default=env.get('NOSE_ARGV_ERRORS'),
dest="argvErrors", help="Add argv to error"
" output by attempting to evaluate failed"
" asserts [NOSE_ARGV_ERRORS]")
def
configure(self, options, conf):
if not self.can_configure:
return
self.enabled = options.argvErrors
self.conf = conf
def formatFailure(self, test, err):
"""Add detail from traceback inspection to error message of a failure.
"""
ec, ev, tb, arg = err
tbinfo = inspect_traceback(tb)
test.tbinfo = tbinfo
for arg in sys.argv:
if arg ==
'--mysql':
return (ec, '\n'.join([str(ev), tbinfo]), tb, 'myql')
elif arg == '--psql':
return (ec, '\n'.join([str(ev), tbinfo]), tb, 'psql')
-------------------------------------------------------------------------------------------
But, i am not getting any sys.argv in the traceback, could you give me any hint ? if possible ?
i am using --mysql in the command line
Thanks,
-Kamal.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20110713/8eb9a3bb/attachment.htm>
More information about the testing-in-python
mailing list