AttributeError ( 'module' object has no attribute 'test_TC1' )

Asked by Anuj Alhans on 2017-04-19

#I have a "ScriptA" whose methods are being called from "MainScript". But I am getting below error in console:

#[error] AttributeError ( 'module' object has no attribute 'test_TC1' )

#Any help would be highly appreciated.

################################################################################################################

#ScriptA.sikuli

#################################################################################################################

from sikuli import*
import unittest

Class A(unittest.TestCase):

    def test_TC1(self):
        ##Some Code

################################################################################################################

#MainScript.sikuli

################################################################################################################

from sikuli import *
import ScriptA
reload(ScriptA)
from ScriptA import *
import unittest
import HTMLTestRunner

def main():
    ScriptA.test_TC1()
    suite = unittest.TestLoader().loadTestsFromTestCase(A)
    outfile = open("C:\Sikuli Reports\A.html", "wb")
    runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='A Test Report', description='This is a Test Report' )
    runner.run(suite)
    outfile.close()

if __name__ == '__main__':
    main()

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-04-19
Last reply:
2017-04-19
RaiMan (raimund-hocke) said : #1

name test_TC1 is not known in the scope of ScriptA, since it is defined inside class A.

recommendation for setup and naming in the SikuliX context:

# ScriptA.sikuli
from sikuli import*
import unittest

ClassTestA(unittest.TestCase):

    def test_TC1(self):
        ##Some Code

#MainScript.sikuli
#from sikuli import * # not needed in mainscript

import ScriptA

# no longer needed with version 1.1.1 since auto reloaded internally
#reload(ScriptA)
#from ScriptA import *

import unittest
import HTMLTestRunner

suite = unittest.TestLoader().loadTestsFromTestCase(TestA)
outfile = open("C:\Sikuli Reports\A.html", "wb")
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title='A Test Report', description='This is a Test Report' )
runner.run(suite)
outfile.close()

with SikuliX script runner there is no need for the main constructions.

#ScriptA.test_TC1()
this does not make any sense, since your tests are run with the HTMLTestRunner anyways.

generally: use version 1.1.1

RaiMan (raimund-hocke) said : #2

sorry, must be

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

Anuj Alhans (anujalhans) said : #3

Hi Raiman,

Thanks for the quick response on this. But my problem is still not resolved.

In my ScriptA.Sikuli , I have 6-7 methods which I have defined inside a class named as "ClassTestA".

And I want to execute only few methods from this list of methods defined in "ClassTestA".

And this execution, I want to do from my "MainScript.sikuli".

I tried using your solution mentioned above, but with this I guess all the methods would be executed.

Request you to please suggest a solution for the same.

RaiMan (raimund-hocke) said : #4

since you are using HTMLTestRunner, you are using Python unittest under the hood.

please read the docs to learn how to create a suite of the testmethods you want to run:
https://docs.python.org/2/library/unittest.html#module-unittest

there are some options how to setup the suite to be given to the Runner.

Surely there are tons of tutorials about Python unites in the net.

Can you help with this problem?

Provide an answer of your own, or ask Anuj Alhans for more information if necessary.

To post a message you must log in.