sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #36822
Re: [Question #284591]: How to handle a complex Python module structure of SikuliX scripts and separate image folder
Question #284591 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/284591
Karl posted a new comment:
This kept bothering me so I tinkered some more and came up with these
two functions to help import the sikuli files. This works with unittest
as it gives a TestSuite with tests named like this:
Application.Area1.SubArea1.Tests.ClassName testMethod=Test1. This
assumes a standard testclass (sikuli_runall) that defines tests for each
*.sikuli test.
import unittest
import imp
import os
import warnings
warnings.simplefilter("ignore", RuntimeWarning) ## used because Python complains that this isn't a real absolute path.
MainDirectory = "C:\\Users\\User\\Desktop" ## important to not have
trailing slash
def getImportName(folder):
name = os.path.basename(folder)[:-7]
folder = os.path.dirname(folder)
while folder != MainDirectory:
name = folder[len(os.path.dirname(folder))+1:]+"."+name
folder = os.path.dirname(folder)
return name
def sikuli_import(sikuliFolder):
sikuliFile = os.path.basename(sikuliFolder)[:-7]+".py"
wholePath = os.path.join(sikuliFolder,sikuliFile)
return imp.load_source(getImportName(sikuliFolder), wholePath)
if __name__ == '__main__':
myScriptPath = "C:\\Users\\User\\Desktop\\Application\\Area1\\SubArea1\\sikuli_runall.sikuli" ## No trailing slashes again!
suite = unittest.defaultTestLoader.loadTestsFromModule(sikuli_import(myScriptPath))
unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(suite))
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.