如何通过使用easygui选择测试来一个接一个地运行python脚本?

问题描述:

我正在使用下面的代码来选择我想要一个接一个地运行的测试。如何通过使用easygui选择测试来一个接一个地运行python脚本?

from easygui import * 
import sys,os 

msg="Select following tests for testing" 
title="Test Selector" 
choices=["Test_case","Test_case2"] 
choice=multchoicebox(msg,title,choices) 


print choice 
msgbox("You have selected:"+str(choice)) 
msg="Do you want to continue?" 
title="Please confirm" 
if ccbox(msg,title): 
    pass 
else: 
    sys.exit(0) 

def func(): 
    for tests in choice: 
     print "tests",tests 
    return tests 
def main(): 

    execfile('python'+' ' +str(func())+'.py') 

main() 

现在选择我想要运行这些测试之一other.I后想使用的execfile试验后,但它说

IOError: [Errno 2] No such file or directory: 'python Test_case.py'

任何人都可以帮我吗?

+0

为什么不会将exec导入它呢?你应该摆脱'“python”+“”' – abccd

+0

tmp = importlib.import_module(测试)如果我尝试使用它,它只运行第一个脚本,我该如何让它运行所有脚本? – user1681102

你不需要的'python'传递到文件的名称...

execfile('Test_case.py') # willl work 

或在您的情况

execfile(str(func())+'.py') 

看吧:

+0

如果我选择多个测试,它会尝试一个接一个地执行2个python脚本吗? – user1681102

+0

tmp = importlib.import_module(测试)会这样吗? – user1681102