How to fail a python unittest if the setUpClass throws exception

前端 未结 4 2105
我在风中等你
我在风中等你 2021-02-13 21:49

I am having little trouble using the python setUpClass.

For example consider the following case

class MyTest(unittest.case.TestCase):

    @classmethod
          


        
4条回答
  •  礼貌的吻别
    2021-02-13 22:56

    The best option would be is to add handler for the except which calls tearDownClass and re-raise exception.

    @classmethod
    def setUpClass(cls):
        try:
            super(MyTest, cls).setUpClass()
            # setup routine...
        except Exception:  # pylint: disable = W0703
            super(MyTest, cls).tearDownClass()
            raise
    

提交回复
热议问题