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

5

151

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.

Dottydoty answered 12/5, 2011 at 8:16 Comment(1)
Any idea how to do it programatically?Doralynn
D
229

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)

Dentilabial answered 12/5, 2011 at 8:49 Comment(5)
Thanks for the useful answer. I also found it helpful to know I could pass this argument into nose.main() as described in the post: #7071001Fachan
In case anyone want to see the source: nose.readthedocs.org/en/latest/plugins/capture.htmlCampos
The short version of this command is nosetests -s. For other standard options, see either the -h help or the basic usage help page.Elaterite
python3.5 -m "nose" --nocaptureAntiperistalsis
doesn't work for me, even with this option my print statements aren't printed when the tests passTetragram
S
17

Use

--nologcapture 

it worked for me

Strachan answered 24/9, 2013 at 9:30 Comment(0)
M
10

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

nosetests -s
Mota answered 11/2, 2015 at 15:51 Comment(3)
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.Whoredom
@BhargavRao "do this nosetests -s" answers the question (albeit, without the littlest regard for grammar). i'm not sure why you're objecting.Forestaysail
Note that -s is the single letter abbreviation of the --nocapture flag as per the documentation.Creedon
D
3

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',
)
Doralynn answered 6/8, 2014 at 13:15 Comment(0)
R
1

Try this,

nosetests -v 2 -s yourtest

Flags expect order.

Reinert answered 11/3, 2021 at 9:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.