我已經編寫了這個演示腳本來問我關於subprocess.call()
的問題 我試圖一個接一個地運行python測試腳本。當其中一個由於無效測試條件而導致的測試中止時,我想終止subprocess.call()
,然後轉到下一個測試腳本。我已經通讀了其他查詢,但沒有找到足夠的解釋。請在此方面感謝任何建議或幫助。在演示文件teminate subprocess.call('python script「)並且繼續執行下一個測試腳本查詢
文件1:listscripts.py
- >此文件列表從文件夾中的所有測試,並將它們用subprocess.call()
import os
from subprocess import *
import sys,os,time
Lib_Path = "C:\\Demo\\question"
sys.path.append(Lib_Path)
import globalsvar # has a global variable
list = os.listdir("C:\\Demo\\question\\scripts") # this has 3 example basic script
for testscripts in list:
aborttest = globalsvar.aborttestcall # when it encounters invalid condition from testscript1thru3 call() should terminate and go to next test
while not aborttest:
Desttestresultpath = os.path.join('C:/Demo/question/scripts',pyscripts)
call(["python",Desttestresultpath]) #calls individual scripts
aborttest = True
exit(1)
文件2:globalsvar.py (aborttestcall = False)
testscript1.py
,testscript2.py
和testscript3.py
- >具有放置在C:/Demo/question/scripts
testscript1.py
和testscript3.py
一些打印statments:
import sys,os,time
Lib_Path = "C:\\Demo\\question"
sys.path.append(Lib_Path)
import globalsvar
print "Start of Test\n"
print "testing stdout prints --1"
time.sleep(1)
globalsvar.aborttestcall = False
print "testing stdout prints --2"
time.sleep(1)
print "testing stdout prints --3"
time.sleep(1)
testscript2.py
:
import sys,os,time
Lib_Path = "C:\\Demo\\question"
sys.path.append(Lib_Path)
import globalsvar
print "Start of Test\n"
print "testing stdout prints --1"
time.sleep(1)
globalsvar.aborttestcall = True
print "testing stdout prints --2"
time.sleep(1)
print "testing stdout prints --3"
time.sleep(1)
我可能沒有正確地說出口。如果你想一個接一個地運行這些腳本,爲什麼不在失敗時退出子進程,而是使用這樣的全局變量? – ferdy