我写了这个演示脚本来问我关于subprocess.call()
的问题。
我正在尝试一个接一个地运行python测试脚本。但是在这个场景中,当一个测试由于无效的测试条件而中止时,我想终止subprocess.call()
。然后继续下一个测试脚本。我已经阅读了其他问题,但找不到充分的解释。感谢你在这件事上的任何建议或帮助。下面是演示文件。你知道吗
File1:listscripts.py
->;此文件列出文件夹中的所有测试,并使用子流程调用()
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
:
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)
您可以这样运行脚本(在不同的可能性中):
而您的内部脚本可以使用一个退出代码退出其进程,您可以对调用进程进行评估。你知道吗
相关问题 更多 >
编程相关推荐