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"
parser = argparse.ArgumentParser(prog=PROGRAM_NAME, description=PROGRAM_DESCRIPTION)
parser.add_argument('--version', action='version', version='%(prog)s ' + PROGRAM_VERSION)
args = parser.parse_args()
When I run it with the --version
param, or --help
, it prints everything OK:
$ bin/test --version
name 0.0.1
$ bin/test --help
usage: name [-h] [--version]
desc
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
When I run the file using subprocess.check_output
, it doesn't get anything:
>>> subprocess.check_output(["bin/test", "--help"], stderr=subprocess.STDOUT, shell=True)
''
>>> subprocess.check_output(["bin/test", "--version"], stderr=subprocess.STDOUT, shell=True)
''
I'm using Ubuntu 11.10 with Python version:
python --version
Python 2.7.1+
I need to get the script output in tests. How should I do that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…