Import sikuli from unit test

Asked by Elisabeth Svensson

Hi!
I know this is a common subject on FAQ, but I cannot get this to work.
I have read through the following links (and more) thoroughly:
http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-reuse-code-and-images
https://answers.launchpad.net/sikuli/+question/129031
https://answers.launchpad.net/sikuli/+question/127275
https://answers.launchpad.net/sikuli/+question/128341
https://answers.launchpad.net/sikuli/+question/146640
https://answers.launchpad.net/sikuli/+question/144555

I am trying to call an imported function from within a unit test. Is this possible?
My code looks like this:
Unit test
==========
myLib = "C:\\Users\\Lisa\\Documents\\Sikuli"
if not myLib in sys.path: sys.path.append(myLib)
import tools
from tools import *
def setUp(self):
        print "open"
def tearDown(self):
        print "close"
def testA(self):
        foobar()
        return True

Imported tool doc
================
from sikuli.Sikuli import *
def foobar():
   pass

I am not very familiar with unit testing or the usage of "self", so I have tried varied forms of this. Like, for instance,
def testA(self):
        self.foobar()
        return True

I only get imports to work if I don't use unit testing.

I'm sorry to post yet another question on this subject, but I have honestly been trying everything I could think of, and I can not make this work.
Best regards

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Elisabeth Svensson
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Sorry, that will never work with the current implementation of the IDE unit test feature.

If you want to use imported stuff, you have to make your own unit test classes and test runs using the unittest module.
look: http://docs.python.org/library/unittest.html

Revision history for this message
Elisabeth Svensson (elisv123) said :
#2

Oh okay, thank you!