nosetests is capturing the output of my print statements. How to circumvent this?

PythonNosetests

Python Problem Overview


When I type

$ nosetests -v mytest.py

all my print outputs are captured when all tests pass. I want to see print outputs even everything passes.

So what I'm doing is to force an assertion error to see the output, like this.

class MyTest(TestCase):

    def setUp(self):
        self.debug = False

    def test_0(self):
        a = .... # construct an instance of something
        # ... some tests statements
        print a.dump()
        if self.debug:
            eq_(0,1)

It feels so hackish, there must be a better way. Enlighten me please.

Python Solutions


Solution 1 - Python

Either:

$ nosetests --nocapture mytest.py

Or:

$ NOSE_NOCAPTURE=1 nosetests mytests.py

(it can also be specified in the nose.cfg file, see nosetests --help)

Solution 2 - Python

Use

--nologcapture 

it worked for me

Solution 3 - Python

This was added recently to nose instead of --nocapture do this:

nosetests -s

Solution 4 - Python

In order to integrate with http://travis-ci.org I have put this into .travis.yml:

script:  "python setup.py nosetests -s"

where setup.py contains:

setup(
    ...
    tests_require=['nose>=1.0'],
    test_suite='nose.collector',
)

Solution 5 - Python

Try this,

nosetests -v 2 -s yourtest

Flags expect order.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFrankie RiberyView Question on Stackoverflow
Solution 1 - PythoncodeapeView Answer on Stackoverflow
Solution 2 - PythonDamianView Answer on Stackoverflow
Solution 3 - PythonmoeabdolView Answer on Stackoverflow
Solution 4 - PythonYauhen YakimovichView Answer on Stackoverflow
Solution 5 - PythonHenshal BView Answer on Stackoverflow