pythonsubprocessphantomjsmocha.jsmocha-phantomjs

mocha-phantomjs output not shown when run with Python subprocess.check_output


Guessing this is something to do with STDOUT/STDERR redirection, but the console output is not displayed when running

#!/usr/bin/env python
import subprocess
subprocess.check_output('mocha-phantomjs static/js/tests/headless.html'.split())

The same command in the terminal prints out all the test output


Solution

  • check_output() captures subprocess' stdout. Use check_call() to avoid redirecting stdout:

    #!/usr/bin/env python
    from subprocess import check_call
    
    check_call(['mocha-phantomjs', 'static/js/tests/headless.html'])