Skip to content Skip to sidebar Skip to footer

Getting Output From Python Script In Python Tests

I've got a simple python script in file 'bin/test': #!/usr/bin/env python import argparse PROGRAM_NAME = 'name' PROGRAM_VERSION = '0.0.1' PROGRAM_DESCRIPTION = 'desc'

Solution 1:

If you're using shell=True, don't pass the program and its arguments as a list. This works:

subprocess.check_output("bin/test --help",  stderr=subprocess.STDOUT, shell=True)

Edit: of course, leaving shell as False would have worked too.

Edit2: the documentation explains why

On Unix, with shell=True: If args is a string, it specifies the command string to execute through the shell. This means that the string must be formatted exactly as it would be when typed at the shell prompt. This includes, for example, quoting or backslash escaping filenames with spaces in them. If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional arguments to the shell itself.


Post a Comment for "Getting Output From Python Script In Python Tests"