← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #182883]: How to run sikuli scripts one by one? and generate the execution results

 

Question #182883 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/182883

RaiMan proposed the following answer:
Then you have to dive deeper:

Have a look at the class TestResult
(http://docs.python.org/library/unittest.html#unittest.TestResult), that
you have to subclass and overwrite the function addSuccess(test).

But in the consequence, you cannot use the text-test-runner, because it
internally uses its own subclassed TestResult (TextTestResult) (or let's
say, I did not figure out yet, how to manage this with the text-test-
runner ;-)

Here is an example to illustrate what I mean:

In this case, an additional message is added on failure.

import unittest

class TestSik(unittest.TestCase):
    def setUp(self):
        print "\n*** in setUp"
    def test1(self):
        print "*** in Test1"
        assert False
    def test2(self):
        print "*** in Test2"
        assert True
    def tearDown(self):
        print "*** in tearDown"


class myTestResult(unittest.TestResult):
    def addFailure(self, test, err):
        print "\n*** from addFailure",test, err
        unittest.TestResult.addFailure(self,test,err)

tr = myTestResult()

suite = unittest.TestLoader().loadTestsFromTestCase(TestSik)
suite.run(tr)

print "*** Test summary ----------------"
print "Tests run:", tr.testsRun
if tr.wasSuccessful():
    print "no Failures"
    exit(0)
print "Failures:", len(tr.failures)
print "--------------"
for e in tr.failures: 
    print "*** FAIL:", e[0]        
    x = e[1].split("\n")
    x1 = " ".join(x[1].split(",")[1:3])
    print "%s ( %s )"%(x1, x[2].strip())
    print "--------------"
exit(1)

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.