Adventures in Nose: nosetests and unbuffered stdout.Posted: March 6, 2009
In some of our server code, we like to insure we get unbuffered output, like in perl. In Python, this is easy to do:
import sys sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
However, using the wonderful nosetest for testing will barf on this code, because it reassigns stdout to a cStringIO for capturing.
This is a workaround:
import sys import os try: # get unbuffered output sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) except AttributeError, exc: # under nose, sys.stdout is reassigned to a string buffer pass def test(): assert 1
Alternately, run nosetests -s, which disables the output capture feature.