这是一个有点奇怪的问题,但我有一堆自动化脚本(使用 Sikuli/Jython),我想从父脚本运行以进行回归。现在我还有一种方法可以捕获要记录到文本文件的异常。所以这是它目前的工作方式:
Master Script --> specific test script
--> specific test script
--> etc (how ever many scripts there are)
我正在和我的一个朋友交谈,他建议每个脚本处理自己的错误,并且父脚本只打开一个文件,使文件位置成为全局变量,子脚本只是附加到该文件。
基本上,我是否需要在 python 中做任何特别的事情才能做到这一点?还是主脚本基本上只是“接触”其他脚本可以使用的文件。
这是“父脚本”的示例(其中没有任何处理错误的代码,也没有打开文件,只是执行脚本)
for dirpath, dirnames, filenames in os.walk("c:\directory\to\the\scripts"):
for filename in [f for f in filenames if f.endswith(".py")]:
directory.append(os.path.join(dirpath, filename))
for entry in directory:
execfile(entry)