有一个项目。该项目有一个文件夹tests
,其中存放各个测试文件,并run_tests
使用以下函数运行所有测试文件main
:
def run_script(script):
subprocess.Popen(["python3", "-Wignore", "-m", script])
def main():
for file in os.listdir('tests'):
run_script('tests.{}'.format(file.split('.')[0]))
if __name__ == "__main__":
main()
使用命令从终端启动python -m tests.run_tests
。所有文件均正常工作,但该过程未在终端中完成。
我在代码中添加了sys.exit()
、、、sys.exit(0)
(最后两个是糟糕的选项)——但这没有帮助exit()
。quit()
该怎么办?
更新
使用不当
subprocess
。工作原理如下: