Question

After running into trouble trying to set the python unittest discover pathway for my project, I'm trying again with nose. I am trying to print out verbose output which is supposedly captured by default by Nose (according to http://nose.readthedocs.org/en/latest/plugins/capture.html)

I have:

arg =sys.argv[:1]
arg.append('--verbosity=2')
out = nose.run(module=ft1.test_y1, argv=arg)

but 'out' is a boolean

How can I get it working?

Was it helpful?

Solution

Your best bet would be to disable the plugin and capture standard output with some other means, for example as described here:

import sys
import nose
from cStringIO import StringIO    

def basic_test():
    print "hello"

if __name__=="__main__":
    module_name = sys.modules[__name__].__file__

    old_stdout = sys.stdout
    sys.stdout = mystdout = StringIO()
    result = nose.run(argv=[sys.argv[0],
                            module_name,
                            '-s'])
    sys.stdout = old_stdout
    print mystdout.getvalue()

When running it like this you will get:

.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
hello
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top