ipython qtconsole print unittest messages in console instead his own window. #2714

Closed
ardling opened this Issue Dec 22, 2012 · 1 comment

2 participants

@ardling

in ipython 0.13.1, ipython qtconsole print unittest messages in console instead his own window.

in ipython qtconsole window:

Python 2.7.3 (default, Jun 12 2012, 16:43:53) 
Type "copyright", "credits" or "license" for more information.

IPython 0.13.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.

Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.


In [1]:%run test.py

In [2]:

in console when ipython running:

#> ipython qtconsole --pylab=inline
/usr/lib64/python2.7/site-packages/pygments/plugin.py:39: UserWarning: Module argparse was already imported from /usr/lib64/python2.7/argparse.pyc, but /usr/lib64/python2.7/site-packages is being added to sys.path
  import pkg_resources
[IPKernelApp] To connect another client to this kernel, use:
[IPKernelApp] --existing kernel-2957.json
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

test.py:

 #!/usr/bin/env python                                                                                                    

 import unittest

 class TestSequenceFunctions(unittest.TestCase):
     def test_work(self):
         self.assertTrue(True)

 if __name__ == '__main__':
     unittest.main()
@minrk
IPython member

I believe this is because unittest hooks up directly with sys.__stderr__. IPython only redirects the public sys.stderr and sys.stdout to the frontends.

So a fix for your script is to tell it to use a regular stream:

if __name__ == '__main__':
    unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout))
@minrk minrk closed this Jul 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment