What I need is very simple, output for every error something that
Eclipse is able to parse in the form
for example filename:line.
I didn't find any doc about how to do these kind of things, so I started
to do something like this:
class MyRunner(object):
def egg_runner(self, eggpath):
conf = Config()
conf.verbosity = 3
eclipse_runner = EclipseFriendlyRunner(stream=conf.stream,
verbosity=conf.verbosity, # why should I pass the config too in theory??
config=conf
)
# and with this the verbosity should be set correctly
TestProgram(argv=argv[:1], config=conf, defaultTest=eggpath,
testRunner=eclipse_runner)
class EclipseFriendlyRunner(TextTestRunner):
def _makeResult(self):
return EclipseFriendlyResult(self.stream,
self.descriptions,
self.verbosity,
self.config)
class EclipseFriendlyResult(TextTestResult):
def addError(self, test, err):
print("this is from my eclipse friendly runner")
super(EclipseFriendlyResult, self).addError(test, err)
But my print statement is never called even in case of errors.
Anyway in general does it make sense what I'm doing?
Seems that overriding _makeResult should not be a good thing to do,
but I didn't see anything better..
And another question, has the API been stable enough through versions
(past and future) or I am going to run into troubles?
From some analysis looks like it's not a great idea, I probably should
write a plugin and enable it,
is that right?
I'm trying to write my own plugin and looking here and there I get the
following (at the moment).
The thing is that I'm not quite sure how to enable it, and how to get
the output of the plugin to
substitute the normal output.
For example xunit only allows to write on a separate file and the output
remains untouched,
so how do I just susbtitute the default formatter in general?
class EclipseFriendlyPlugin(Plugin):
"""Nose plugin to output errors in a format that is easily parsable
by Eclipse
"""
name = 'eclipse_friendly'
encoding = 'UTF-8'
def __init__(self):
self.errorlist = []
super(EclipseFriendlyPlugin, self).__init__()
def _format_error(self, level, test, err):
fname, lineno = _location_from_traceback(err)
return "%s %s: (%s:%d)" % (level, test.id(), fname, lineno)
def options(self, parser, env=os.environ):
super(EclipseFriendlyPlugin, self).options(parser, env=env)
def configure(self, options, config):
"""Configures the xunit plugin."""
Plugin.configure(self, options, config)
self.config = config
if self.enabled:
self.stats = {
'errors': 0,
'failures': 0,
'passes': 0,
'skipped': 0
}
def addError(self, test, err, capt=None):
if issubclass(err[0], SkipTest):
err_type = 'skipped'
self.stats['skipped'] += 1
else:
err_type = 'error'
self.stats['errors'] += 1
self.errorlist.append(self._format_error("error", test, err))
def addFailure(self, test, err):
self.stats['failures'] += 1
msg = self._format_error("failure", test, err)
self.errorlist.append(msg)
I can't find, however, a single helpful example or a hint about how to do it
(and I would be pleased to share my code in the nose website when it's
working).
Any suggestions?
class NoseTestRunner(object):
def egg_runner(self, eggpath):
"""Run all the tests in the given egg
"""
conf = Config()
conf.verbosity = 3
ep = EclipseFriendlyPlugin()
# how do I make sure the plugin is actually loaded and doing
something?
ep.enabled = True
# how do I actually enable it?
plugins = [ep]
# and with this the verbosity should be set correctly
# should use addplugins instead if they are not "default" plugins
TestProgram(argv=argv[:1], config=conf, defaultTest=eggpath,
plugins=plugins)
class EclipseFriendlyPlugin(Plugin):
"""Nose plugin to output errors in a format that is easily parsable
by Eclipse
"""
name = 'eclipse_friendly'
encoding = 'UTF-8'
def __init__(self):
self.errorlist = []
self.successlist = []
super(EclipseFriendlyPlugin, self).__init__()
def _format_error(self, level, test, err):
fname, lineno = _location_from_traceback(err)
return "%s %s: (%s:%d)" % (level, test.id(), fname, lineno)
def options(self, parser, env=os.environ):
super(EclipseFriendlyPlugin, self).options(parser, env=env)
def configure(self, options, config):
"""Configures the xunit plugin."""
Plugin.configure(self, options, config)
def addError(self, test, err, capt=None):
# if returning something other plugins will not see the error
raised
self.errorlist.append(self._format_error("error", test, err))
def addFailure(self, test, err):
self.errorlist.append(self._format_error("failure", test, err))
def addSuccess(self, test):
self.successlist.append(test.id())
def report(self, stream):
# should I force the unicode here too maybe or not care about it?
for error in self.errorlist:
stream.writeln(error)
ep = EclipseFriendlyPlugin()
# how do I make sure the plugin is actually loaded and doing
something?
plugins = [ep]
# and with this the verbosity should be set correctly
# should use addplugins instead if they are not "default" plugins
TestProgram(argv=argv[:1], config=conf, defaultTest=eggpath,
addplugins=plugins)
but it doesn't work, I get a :
File "/home/andrea/.local/bin/run_tests", line 9, in <module>
load_entry_point('psi.devsonly==0.1', 'console_scripts', 'run_tests')()
File
"/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/bin/run_tests.py",
line 62, in main
modes[ns.mode]()
File
"/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/bin/run_tests.py",
line 42, in simple
print(NoseTestRunner().egg_runner(ns.project_path))
File
"/home/andrea/git_projs/Psi/psi.devsonly/psi/devsonly/testwrapper.py",
line 60, in egg_runner
addplugins=plugins)
File "/usr/lib/python2.7/site-packages/nose/core.py", line 107, in
__init__
config.plugins.addPlugins(addplugins)
File "/usr/lib/python2.7/site-packages/nose/plugins/manager.py", line
208, in addPlugins
raise NotImplementedError()
NotImplementedError
I guess that with another PluginManager it might work, but I have no way
apparently to the way
the pluginmanager is actually chosen, am I wrong??
If instead I pass
"plugins=plugins", everything seems fine but the plugin seems to have no
effect whatsoever...
Any hint how to just make a plugin working by default and writing output
on the console??
JP
> --
> You received this message because you are subscribed to the Google Groups
> "nose-users" group.
> To post to this group, send email to nose-...@googlegroups.com.
> To unsubscribe from this group, send email to
> nose-users+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nose-users?hl=en.
>
Good thanks I think I solved this by the way, I was passing
a configuration to increase the verbosity as
conf= Config()
conf.verbosity = 3
So the question is, how do I create a configuration which doesn't
interfere with the addplugins?
(because in Config actually plugins is set to NoPluginManager, which
explains everything).
And another thing, which was the older way of doing the same?
Because actually addplugins is not present in the version I have on
windows (0.10)..