I'm using nose to test an application that uses subprocess.Popen()
to call a script. Neither the capture or logcapture plugin seem to capture the output of this script. Is there an easy way to pipe this output to nose?
Here's what I've attempted so far; note "Capture me" isn't captured:
example.py:
if __name__ == '__main__':
print 'Capture me'
test.py:
import subprocess
import sys
def test_popen():
# nose's capture plugin replaces sys.stdout with a StringIO instance.
# subprocess.Popen() expects stdout to have a fileno property, which
# StringIO doesn't, so fake it.
sys.stdout.fileno = lambda: 1
subprocess.Popen(['python', 'example.py'], stdout=sys.stdout)
assert False # Force test to fail so we see nose output
output:
$ nosetests test.py
F
======================================================================
FAIL: test.test_popen
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/pmdarrow/Envs/example/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/pmdarrow/Code/example/API/test.py", line 8, in test_popen
assert False
AssertionError
----------------------------------------------------------------------
Ran 1 test in 0.004s
FAILED (failures=1)
Capture me