UnitTest stop a whole test suite

Asked by Linda

Not really a question for this forum, but maybe someone can help anyway.

I have a bunch of separate test scripts which I then executes from a test suite using the unittest framwork, like this

------------------------------------------------------------------------

class InstallAndLaunch(unittest.TestCase):
    def test1_myscriptA(self):
        import myscriptA

class Login(unittest.TestCase):
    def test1_myscriptB(self):
        import myscriptB

    def test2_myscriptC(self):
        import myscriptC

------------------------------------------------------------------------

If I add "assert False" in any of the scripts and running the suite, that test will stop running and the next one will start.

What I wonder is if it is possible to stop ALL tests from within my scripts, e.g. if the installation fail, there is no need to run any of the other tests since it wont work.

Hope it makes sense,

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
Eugene S (shragovich) said :
#1

Have a look at setupclass and teardownclass:

https://docs.python.org/2/library/unittest.html#setupclass-and-teardownclass

which execute before and after the tests in a given class are run.
Alternatively, if you have a group of them in one file, you can use setUpModule and tearDownModule

https://docs.python.org/2/library/unittest.html#setupmodule-and-teardownmodule

Revision history for this message
Linda (linda-nordstrom) said :
#2

setupmodule seems to be introduced in python 2.7, is Sikuli supporting that? because I can't seem to get the setUpModule to work, or maybe I am doing it wrong.

def setUpModule():
 assert False

class InstallAndLaunch(unittest.TestCase):
    def test1_myscriptA(self):
        import myscriptA

class Login(unittest.TestCase):
    def test1_myscriptB(self):
        import myscriptB

---------------------------------------------------------------

Running this in a suite, the tests in the classes are still executed. I would have assumed them not to be.

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

with SikuliX 1.1.0 later than 2015-06-01 you have Jython 2.7.0 bundled.

This should support it, since they claim to be Python 2.7 compatible.
If this is not the case, I cannot help you.

Can you help with this problem?

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

To post a message you must log in.