ImagePath: find: not there when importing unittest TestCase into main script

Asked by Aleks Kozaev on 2020-01-17

I have a name.sikuli script which is as follows:

class TestA(unittest.TestCase):
    def testA(self):
        self.assertTrue(1 == 1)

When i run it with

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TestA)

it works fine. Then I tried to create a main script and put name.sikuli into main.sikuli. Code of main.sikuli:

import os
myPath = os.path.dirname(getBundlePath())
if not myPath in sys.path: sys.path.append(myPath)

import name
from name import *

suite = unittest.TestLoader().loadTestsFromTestCase(TestA)

When I tried to run main.sikuli it gave

[error] ImagePath: find: not there: image.png

I tried to use functions from another script (which is not unittest class, just functions) in name.sikuli. The image from this script was found both times, when running name.sikuli and main.sikuli. Is there a problem when importing sikuli script that is a class?

P.S. using SikuliX IDE 2.0.0

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
Aleks Kozaev (aleksboyyy) said : #1

Update: Tried to copy "image.png" to main.sikuli. Now it works. Encountered this problem only when using unittest classes. Regular sikuli classes import fine and I don't have to copy images. Is there a workaround this (maybe specify image path before every test suite). I don't want to copy images from several folders to main.sikuli.

RaiMan (raimund-hocke) said : #2

yes, the solution most probably is to use the ImagePath feature.
Might even be, that an intellgent use of setBundlePath() is sufficient.

If you are using SikuliX 2.x, then you might try to work generally with plain Python files in a folder structure, that is directly compatible with a Python module structure.

First do Ide -> save dialog -> Files of type: as File.
Captured Images will now be stored in the same folder as the .py resides.
all other .py files now share all images in that folder.

IMO in your situation working with Python specific constructs (classes) and features (unittest), not working with .sikuli but with plain .py seems to be more appropriate.

Can you help with this problem?

Provide an answer of your own, or ask Aleks Kozaev for more information if necessary.

To post a message you must log in.