Pass argument to test runner

Asked by Asheru on 2019-01-10

 So my test runner file uses HTML test runner. It basically looks like this:

import sys.argv

if __name__== "__main__":

    unittest.TextTestRunner(verbosity = 2)
    output = open(HagercadConfig.HAGERCAD_HTML_REPORT_FILE,"w+")
    runner = HTMLTestRunner.HTMLTestRunner(stream=output, title=HagercadConfig.HAGERCAD_HTML_REPORT_TITLE, description=HagercadConfig.HAGERCAD_HTML_REPORT_DESCRIPTION)[1])

I want to run the tests from command line and I do either:
 pathToSikuli\Sikuli\runsikulix -r pathToMyTestRUnnerClass\HagercadTestRunner.sikuli --args HagercadTests.regressionSuite()
java -jar pathToSikuli\Sikuli\sikulix.jar -r pathToMyTestRUnnerClassHagercadTestRunner.sikuli --args HagercadTests.regressionSuite()

So i want to pass via command line an argument directly to and of course "HagercadTests.regressionSuite()" is the suite that i want to run wich is located in another file.

I;m getting this error:[1])
  File "C:\Users\rares.pasca\AppData\Roaming\Sikulix\Lib\", line 678, in run
TypeError: 'unicode' object is not callable

I dont know exactly how to fix it.

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Asheru (asheru93) said : #1

forgot some imports at the begninng but it doesnt matter

RaiMan (raimund-hocke) said : #2

can be reduced to this:

#coming from sys.argv[1]:

.... this is a string !!!

but for

parameter must be a test suite object !!!

Hence you first have to convert sys.argv[1] to a valid test suite.

eval() might be helpful ;-)

--- something like"unittest.TestLoader().loadTestsFromTestCase(" + sys.argv[1] ")")

where the parameter in this case must name the Test class.

Best RaiMan (raimund-hocke) said : #3

sorry, a + missing:"unittest.TestLoader().loadTestsFromTestCase(" + sys.argv[1] +")")

Asheru (asheru93) said : #5

Thanks RaiMan, that solved my question.

Asheru (asheru93) said : #6

Is it possible to make it run from outside the class?

I'm trying to make a configuration to run the tests like this from command line.

So i have 200 methods let's say that are steps basically,step1(),step2()...step200(). I want to create a configuration in wich if someone wants to run a test, it gives in the command line :java -jar pathToSikuli -r pathToScript --args step1 step5 step127 and from there my script knows to add those steps into a test and run it.

So i was thinking to create a method that collects the arguments from cmd and adds them to a list and returns it. Then the list is passed to another method wich adds the arguments in list to a test suite. Now the method that creates the test suite is passsed to the Runner file and runs it. Is this to complicated? Or is there a simpler way to do it?

That's why I;m asking if I can run something from outisde a class because I want to add at some point this method that creates a suite and it's outside my test class.

RaiMan (raimund-hocke) said : #7

yes you can - but this is basic Python knowledge.
Has nothing to do with SikuliX.

Asheru (asheru93) said : #8

I'm halfway trough.

I give the following arguments in cmd:

java -jar pathToSikuli -r pathToTestRunner --args MyClass.startApp() MyMethodLocation.createProject()

The class that contains the tests looks like this:

class TestSuites(unittest.TestCase):

    def firstTest(self,aList):
        #steps returned by argumentsCollector()

def argumentsCollector():
    argumentsList = list()
    for i in sys.argv:
    HagercadLogger.Logger.Log(HagercadLogger.LEVEL_WARNING, "PRINT: " + ', '.join(argumentsList))
    return argumentsList

def hagerTests():
    suite = unittest.TestSuite()
    return suite

argumentsCollector() return a list that looks like this [MyClass.startApp(),MyMethodLocation.createProject()]
hagerTest() - is a suite that contains one test, the test inside my unittest class.

Is there a restriction to unittest in it;s default implementation, or i can pass arguments to e method inside a unittest class, like in my method firstTest(self,aList) , where aList would be the list of arguments(action/steps) collected from cmd? And then this method knows that the list is actually some steps in a test.

I'm noob in python unfortunately.

RaiMan (raimund-hocke) said : #9

Sorry, but due to private priorities I have no time to help you the next 2 - 3 weeks.

Asheru (asheru93) said : #10

No problem. In the meantime i hope i will find a solution.

Wish you all the best.