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.

Frankie Ribery
  • 11,933
  • 14
  • 50
  • 64

5 Answers5

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)

codeape
  • 97,830
  • 24
  • 159
  • 188
  • 3
    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: http://stackoverflow.com/questions/7070501/passing-options-to-nose-in-a-python-test-script – David Hall Feb 01 '12 at 15:22
  • 2
    In case anyone want to see the source: http://nose.readthedocs.org/en/latest/plugins/capture.html – Ceasar Jul 27 '12 at 18:30
  • 12
    The short version of this command is `nosetests -s`. For other standard options, see either the `-h` help or the [basic usage](https://nose.readthedocs.org/en/latest/usage.html#selecting-tests) help page. – dbn Apr 16 '13 at 00:17
  • python3.5 -m "nose" --nocapture – Alex Punnen Mar 19 '18 at 09:24
  • 2
    doesn't work for me, even with this option my print statements aren't printed when the tests pass – John Smith Optional Nov 06 '19 at 21:51
17

Use

--nologcapture 

it worked for me

Damian
  • 4,395
  • 4
  • 39
  • 67
10

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

nosetests -s
vvvvv
  • 25,404
  • 19
  • 49
  • 81
moeabdol
  • 4,779
  • 6
  • 44
  • 43
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Bhargav Rao Feb 11 '15 at 16:55
  • 7
    @BhargavRao "do this nosetests -s" answers the question (albeit, without the littlest regard for grammar). i'm not sure why you're objecting. – abcd Apr 18 '15 at 03:23
  • 2
    Note that `-s` is the single letter abbreviation of the `--nocapture` flag as [per the documentation](https://nose.readthedocs.io/en/latest/plugins/capture.html). – joelostblom Oct 11 '18 at 14:54
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',
)
Yauhen Yakimovich
  • 13,635
  • 8
  • 60
  • 67
1

Try this,

nosetests -v 2 -s yourtest

Flags expect order.

Henshal B
  • 1,540
  • 12
  • 13