must import for each unittest test case

Asked by janet

Experimenting with running Unittests with Sikuli X:

/Applications/Sikuli-IDE.app/sikuli-ide.sh -t /Users/janetPCF/Sikuli-testing/Miro/test.sikuli

if I have my tests setup like this:

#test.sikuli

import os
def setUp(self):
    myApp = "/Applications/Miro.app"
    App.open(myApp)
    print os.getenv("SIKULI_TEST_HOME") # an env variable set on my system

def tearDown(self):
    print "my test is done"

def test_mytest(self):
    wait("MiroFileEdit.png")
    click("Sidebar")

The test will fail - with global os not found. In order for os.getenv - to work, I must import it in setup - or any other testcase where I would want to use it.

I expect to need various python and custom modules in my tests, and don't want to have to make the imports for each individual test case.

When I was using 10.2 - things were working as expected. Here's an example: https://github.com/PCF-qa/MVC/blob/master/sg59_apple_devs.sikuli/sg59_apple_devs.py

these tests I was running using this command: java -d32 -Dpython.path=Lib/ -jar sikuli-script.jar MVC/sg59_apple_devs.sikuli

Question information

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

Why did you switch from the approach using unittest directly in 10.2 to using the Sikuli IDE's test wrapping feature?

Revision history for this message
janet (jed-pculture) said :
#2

I'm having a hard time getting my existing tests to run using the unittests directly.

Reading the Sikuli X docs, led me to belive that it was the best approach. I'd prefer my original way - if you can help with that - but I think there's some set up, or a command I am missing.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

When really working towards modularized unittests, I encourage you, to stick with your 10.2-approach and e.g. incorpoate the new possibilities of X: image libraries and import of other .sikuli including images.

With the X 1.0rc2 scheduled for 23rd this month, we will have a solution, to use sikuli-script.jar without any modifications as it comes with the distribution in any usages outside of Sikuli IDE (NetBeans, Eclipse, plain Jython, Java directly, ...).

If you want to have it right now, I can tell you how to do it or (if you trust me ;-) prepare a .zip for you to download and use it (contains a modified Frameworks folder and a modified sikuli-script.jar). I am working with this on my Mac with NetBeans and the upcoming rc2 solution is based on my experiences.

Revision history for this message
janet (jed-pculture) said :
#4

I'd be happy to trust you with the .zip file - I have 100+ tests that I'd like to get automated w/ sikuli before April.

Revision history for this message
janet (jed-pculture) said :
#5

I should also add, that I too am currently working on os x - but my goal is to be able to run the tests on win and linux as well with only minor os-specific variations.

Revision history for this message
RaiMan (raimund-hocke) said :
#6

ok. zip:

I will upload it to my MobileMe and sent you the link.

Since I do not want to spred this copy all over the world, I ask you to send me a personal mail using my address on https://launchpad.net/~raimund-hocke, that I will answer with the link and additional instructions.

Revision history for this message
RaiMan (raimund-hocke) said :
#7

the rc2 solution will be working on all platforms. If you need the solution for Windows and Linux (you know you need to install openCV on your own !?) before, I have it too.

Revision history for this message
janet (jed-pculture) said :
#8

thanks - you should have gotten my email. I can install openCV on linux (found a PPA the other day, https://launchpad.net/~gijzelaar/+archive/opencv2), I can figure it out for windows when I get there.