How to skip all test from setUpClass

I want to skip all the unit-tests if some condition doesn't satisfy under setUpClass function. Like -

@classmethod
def setUpClass(cls):
    if(!condition):
        cls.skipTest("For some reason")

After doing this I'm expecting other unittest cases will not run. But it's showing an error

TypeError: skipTest() missing 1 required positional argument: 'reason'

Upvotes: 2

Views: 897

Answers (1)

Stephen Rauch
Stephen Rauch

Reputation: 49774

You can raise the SkipTest exception like:

@classmethod
def setUpClass(cls):
    if not condition:
        raise unittest.SkipTest("For some reason")

Upvotes: 6

Related Questions