← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #206597]: Problem with importing "external" modules

 

Question #206597 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/206597

    Status: Answered => Solved

CryoGenID confirmed that the question is solved:
Hello Raimund!

It is working now...
I could hit my head against the wall, such a dumb error ;-)

After I copied your demo-code and got the same error message again, I went on and printed out the content
of "sys.path" and there I found out that the directory of the "main"-sikuli script under which the "Tests" directory resides, was not part of that path.

So the simple solution was to include that:
--- 
testsModulePath = os.path.join(dir, "RUNME.sikuli\Tests")
---

And that's it ;-)

So if anybody is interested, here is the working code:
--- 
import InitSystem
import GlobalSettings
import os
dir = os.path.dirname(getBundlePath())
testsModulePath = os.path.join(dir, "RUNME.sikuli\Tests")

modulesToRun = ("Test1", "Test2", "Test_OCR")

print("Testing started: " + InitSystem.getCurrentTime())

if (InitSystem.startUp(GlobalSettings.screenT, GlobalSettings.screenQ, GlobalSettings.screenP)==0): # Init the tests
    popup("ERROR during startup, cancelling all tests...")
    exit
else:    # Startup was OK
    # Iterating through all Test-Modules
    popup("OK starting Tests in Modules")
    
    if not testsModulePath in sys.path:
        sys.path.append(testsModulePath)
    for currentModule in modulesToRun:
       popup("Working with module " + currentModule + " in directory " + testsModulePath)  
       popup("Opening " + currentModule)
       exec("import " + currentModule)
       exec(currentModule + ".runModule()")
    
InitSystem.shutDown() # Shut down the test
print("Testing ended: " + getCurrentTime())
--- 

Thanks a LOT Raimund and best regards,

Christian

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.