0

I am writing a test suite as:

class MySuite(unnitest.Testcase):

@classmethod
def setUpclass(cls):
    try:
        ***some code which will throw exception***
    except Exception as e:
        print('Error Thrown')
@classmethod
def tearDownClass(cls):
    print('In teardown')
def test_demo(self):
    print('In test_demo')

The problem is, though error will be thrown in setup (because of 5/0), the test_demo will be executed, which I do not want to.

What could be the best approach to stop executing the test_demo whenever there is an error in setup method.

1
  • What happens if you remove the try-except in your setup, and just allow the exception to propagate? Commented Apr 1, 2015 at 8:22

1 Answer 1

1

You're catching the error and just printing a message in response. Don't do that.

If you really want to print something, at least re-raise the exception afterwards. But better not to bother catching it at all: the traceback should be sufficient information.

(Also, the first parameter to a classmethod is usually called cls not self, as it is the class itself.)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.