ImportError: Errors in loading sikuli module: unittest

Asked by nupur

Hi,

I'm using Win7 and Sikuli-r930-win32.

I've written this script in Sikuli IDE:

from sikuli import *
from unittest import *
from HTMLTestRunner import *

class BDTests(unittest.TestCase):
    def setUp(self):
        App.open("C:\\Program Files\\Internet Explorer\\iexplore.exe www.google.com")
        wait(2)

    def tearDown(self):
        App.close("C:\\Program Files\\Internet Explorer\\iexplore.exe")
        wait(2)

    def testA(self):
        print("done!!")

suite = unittest.TestLoader().loadTestsFromTestCase(BDTests)
#unittest.TextTestRunner(verbosity=2).run(suite)
outfile = open("C:\Report.html", "w")
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='Test Report', description='This is demo' )
runner.run(suite)
outfile.close()

But when i am running this script, it shows this error:

ImportError: Errors in loading sikuli module: unittest
'module' object has no attribute 'TestResult'
 - HOW TO FIX? Try adding "from sikuli import *" in the module.

Please help me in fixing this issue.
Thanx in Advance!!!

Question information

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

There seems to be some name overlay with Sikuli.

So try this:

# from sikuli import * # not needed in Sikuli main scripts
import unittest
import HTMLTestRunner

And if you want o access something in unittest or HTMLTestRunner use qualification (which is already done in your script:
unittest.TestCase
HTMLTestRunner.HTMLTestRunner
...

Revision history for this message
nupur (nupur) said :
#2

Hi Raiman,

First of all thanks for the reply!!

I've tried your suggestion but now its showing:

 runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='Test Report', description='This is demo' )
AttributeError: type object 'HTMLTestRunner' has no attribute 'HTMLTestRunner'

Revision history for this message
nupur (nupur) said :
#3

My problem is solved :)

The issue was with import statement.

I have changed :
from unittest import *
from HTMLTestRunner import *

to:
import unittest
import HTMLTestRunner

and my script got run.

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

So this was exactly my suggestion in comment #1.
So what was the problem 20 min ago with comment #2?

Revision history for this message
nupur (nupur) said :
#5

Actually i changed "from unittest import *" to "import unitest" but didn't change HTMLTestRunner statement.
Thats y i faced that issue.
Now its working fine.

Thanks again!!!