0

Hi I was asked to write a program which launch an external program test the program. I wrote a python method in one file and imported it into another file and wrote test cases for it.

But I need to launch an external program.

Could someone please help me with what that is and how to do that?

Sun Shine
  • 465
  • 2
  • 6
  • 17
  • Can you please show what have you tried ? please share your code with us – Vipul Jun 09 '14 at 14:48
  • I have updated the code that I wrote in the question, please help. SUT is supposed to be an external application. I wrote it as a python program, I do not know what to do. – Sun Shine Jun 09 '14 at 14:59
  • you might be interested in `nose` library – Vor Jun 09 '14 at 15:05
  • Thanks Mark, I actually looked at that post. subprocess is not working me on Mac with python 2.7. I tried with os.popen(python /path/to/fileToRun.py 1 1) by passing the arguments also, but it is not taking the arguments. – Sun Shine Jun 09 '14 at 23:25

1 Answers1

0

You might be interested in the os library. Comes with python, import os then you can use os.system("unix terminal command") ex.

import os

os.system('python /path/to/fileToRun.py')

EDIT:

not sure why subprocess isn't working but popen should capture everything that is printed with your other classes

result = os.popen('python /path/to/file.py').read()
print result
GleasonK
  • 802
  • 7
  • 16
  • 1
    While technically correct, it is advised to use subprocess over os.system. – Bob Jun 09 '14 at 15:00
  • Good point, subprocesses expand on the functionality of the os library, thank you for that. https://docs.python.org/2/library/subprocess.html – GleasonK Jun 09 '14 at 15:09
  • The method in sut have two arguments and also I want to catch the stdout and stderr in a file log file.log. Do I need to use this: subprocess.check_output("python /pathtoSUT", 'a', 'b', stdout=subprocess.STDOUT, stderr=subprocess.STDOUT, shell=false) – Sun Shine Jun 09 '14 at 18:36
  • I also need to check for the return value from the sut program – Sun Shine Jun 09 '14 at 18:37
  • subprocess is not working me on Mac with python 2.7. I tried with os.popen(python /path/to/fileToRun.py 1 1) by passing the arguments also, but it is not returning the output by taking the arguments. – Sun Shine Jun 09 '14 at 23:26
  • Try adding `os.popen(python /path/to/fileToRun.py 1 1).read()`. and You want the os command to write the log or you want python to write the log? Could you rephrase what you want this command to do? – GleasonK Jun 09 '14 at 23:37