I am getting this error 'module' object has no attribute 'TestCase'

Asked by Steve Brown

 This script runs perfectly when run inside the Sikuli IDE as a Unit Test.
 When I run it from a bat file I get this error 'module' object has no attribute 'TestCase'.

this is my bat file
Sikuli-IDE.bat -r C:\sikuli\Sikuli-r930-win32\Sikuli-IDE\src\idirUnit.sikuli

=====
script
=====

from sikuli import *
import unittest

 ## ... define your tests ...

class TestSequenceFunctions(unittest.TestCase):

 def setUp(self):
  print "in setup"
  popup("in setup")

 def tearDown(self):
  print "in tearDown"
  popup("in teardown")

 def test_aaa_empty(self):
  print "in test"
  popup("in test_empty")
  return True

######### end test defs #####################
suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
unittest.TextTestRunner(verbosity=2).run(suite)

======

Question information

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

the classname is unittest.Testcase

Revision history for this message
Steve Brown (sbrown-d) said :
#2

http://docs.python.org/library/unittest.html

This documentation says unittest.TestCase.

I changed it anyway to unittest.Testcase and got the same error.

I found that my script works in one folder but not another.
In the one it does not work in I can run it from the IDE successfully.
????

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

Sorry for the bullshit: Python doc is right and TestCase is correct.

--1. from sikuli import *
is not needed in main scripts (only in Sikuli scripts that you import)
but should not be the cause of the problem

--2. I can run it from the IDE successfully.
in normal run mode or in the UnitTest view?
Normal run mode should not work either, if it does not work with the .bat
In the UnitTest view only the def()'s are seen and wrapped into an internal Java unittest runner.

Make this script:

import unittest
class SomeTest(unittest.TestCase):
    pass

and run it normally in the IDE.

Revision history for this message
Steve Brown (sbrown-d) said :
#4

  I have a good folder and a bad folder

C:\sikuli\Sikuli-r930-win32\Sikuli-IDE\src\fusebox\panelsUnit.sikuli
is where I successfully created my first test app. It runs perfectly.

I tried creating my second test app here
C:\sikuli\Sikuli-r930-win32\Sikuli-IDE\src\idirUnit.sikulii
I get the 'module' object has no attribute 'TestCase' error here.

I can solve my problem by copying idirUnit bad under fusebox so I have this
C:\sikuli\Sikuli-r930-win32\Sikuli-IDE\src\fusebox\idirUnit.sikuli.

I repeated this with your test.
I created 2 raiman.siklui folders one under fusebox and the other outside.

C:\sikuli\Sikuli-r930-win32\Sikuli-IDE\src\raiman.sikuli

I get the following when trying to run here
[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.

[info] VDictProxy loaded.

[error] Stopped
[error] An error occurs at line 2
[error] Error message: Traceback (most recent call last):
 File "C:\Users\SBROWN~1.VMT\AppData\Local\Temp\sikuli-tmp3904348854941594047.py", line 2, in
 class SomeTest(unittest.TestCase):
AttributeError: 'module' object has no attribute 'TestCase'

C:\sikuli\Sikuli-r930-win32\Sikuli-IDE\src\fusebox\raiman.sikuli

Running in this folder works fine

Operating system is Windows 7 64 bit

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

So it seems to be a problem with some irritating content in the folders when running them from
C:\sikuli\Sikuli-r930-win32\Sikuli-IDE\src

It looks like the unzipped downloaded stuff from the latest build.
I will only have a chance to check this on my Win7 system on friday.

So simply store your scripts somewhere else in a clean folder structure meanwhile.

Revision history for this message
Steve Brown (sbrown-d) said :
#6

  I created a c:\mySikuli folder, copied my work into it and all is well.
 c:\mySikuli\idirUnit.sikuli

  Win7 is interesting. :-)

Can you help with this problem?

Provide an answer of your own, or ask Steve Brown for more information if necessary.

To post a message you must log in.