← Back to team overview

sikuli-driver team mailing list archive

[Question #304447]: How to reaload module which has been imported by a string

 

New question #304447 on Sikuli:
https://answers.launchpad.net/sikuli/+question/304447

Hi all,

In my testing environment, I want to load modules of test cases at runtime from a list defined in a setupEnvironment.py file
Here is the code in the main script to load modules:

import setupEnvironment                #it is from setupEnvironment.py file 
reload(setupEnvironment)

TestCaseList = setupEnvironment.TestCase_List         #get list of test cases (each test case is defined in a sikuli module)
TestCaseDir = setupEnvironment.TestCase_Dir
ParentPath = getParentPath()

test_id = 0
for test_name in TestCaseList:
    testmodule_path = getParentPath() + "\\" + TestCaseDir[test_id][test_name] + ".sikuli"       #get path to sikuli folder of test case
    testmodule_name = TestCaseDir[test_id][test_name]
    if testmodule_path not in sys.path:
        sys.path.append(testmodule_path)
    test = __import__(testmodule_name)                      #load sikuli module of the test case
   ### how to reload the the test case here ???? ########   
    test.MainEntry()                       #execute the test case
    test_id += 1

I want to know which command I can use to make Sikuli reload the test module when it runs?
Since I may be making changes to the test modules and run the main script many times. Now each time, I need to restart the IDE to make it reloads.

Note: This case, I load the module by using a string defined in "testmodule_name" variable.
 I tried with "reload(testmodule_name)" but it reports that reload() requires module object, not string object

Thanks,
HuyK

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.