python动态导入,用于使用eval执行测试脚本

时间:2017-02-21 07:18:41

标签: python

我正在研究一个基本上尝试从包含所有脚本的包运行测试脚本的框架。

在我的执行驱动程序文件中:

目前我正在做的是from testscripts import testscript1from testscript import testscript2等等。

我正在从sys.argv[1]

获取脚本名称
test_name = sys.argv[1]

并使用eval函数运行该脚本。

testscript skeleton:

##testscript1.py
class testscript1:
    def runTest():
        {
            ## tests to run
        }

eval函数调用:

eval(test_name+"."+test_name+".runTest()")

为此我需要单独导入每个测试脚本名称。 我想做什么,比如来自testscripts import *。

如果我这样做,那么我得到error: name 'testscript1' is not defined.

非常感谢任何帮助。

0 个答案:

没有答案